![]() ![]() Twoway `plot2', legend(off) ylab(`yrange') xlab(0 (1) `xmax', val) xtitle(color) ytitle(intensity) **plot with two labels and square swatches Graph export `testname'_sample_color_swatch.png, replace Twoway `plot', legend(off) ylab(.25 (.25) 2) xlab(0 (1) `xmax', val) xtitle(color) ytitle(intensity) ** plot with just the colornames and round swatches Local testname "test_today" // give a unique name to the output file Local xmax=`ncolor'+1 // put an extra column of padding in the table *disp "`plot'" // in case you need to check whether it worked Local plot2 "`plot2' (scatter inten int2 colornum if col_int_num=`point', ms(S none) mcolor(`colorname' `colorname') msize(*3 *3) mlab( RGB_derived colorname) mlabc(`colorname' `colorname') mlabsize(vsmall vsmall) mlabpos(6 6))" Local plot "`plot' (scatter inten colornum if col_int_num=`point', mcolor(`colorname') msize(huge) mlab(colorname) mlabc(`colorname') mlabsize(tiny) mlabpos(6))" ** collect the plots for each point in locals named plot and plot2 Local colorname: label col_int_num `labelnum' Qui summ col_int_num if col_int_num=`point' **get the values for each point in the plot Gen int2=inten-`labgap' // slightly lower value on vertical axis ** gen a value of inten just a little lower to carry the second label Gen RGB_derived=string(Rx)+" "+string(Gx)+" "+string(Bx) Replace `CC'x=round(`CC'o/inten,1) if inten>1 Qui replace RGB_base="`3'" if basecolor="`base'" *qui replace lab=`""`3'`basemod'""' in `i' // the code from full_palette.ado Local colorfile=r(fn) // findfile returns the file locationįile open `hdl`base'' using "`colorfile'", read text Tempname hdl`base' // assigns a tempfile nameįindfile color-`base'.style // this command searches all ado directories ** I did not copy all the error code returns ** and extracts the RGB values for that color and puts it in a variable RGB_base ** it finds and reads the color style file for each named color ** this code snippet taken from full_palette.ado with modifications Gen inten=real(intenS) // this is the actual numeric value of intensity ** uses the string variables as value labels for the numerical variables Replace col_int_num= ii' if case=ii' local ii=`ii'+1 } } Replace intenS=word("`intenlist'",`inten') if case=`ii' Replace basecolor=word("`colorlist'",`color') if case=`ii' ** fill in the strings with colors and intensities ** This code generates the data for the plotsĭisp "ncolor `ncolor' ninten `ninten' ncases `ncases'" Local yrange "`lowint' (`edgegap') `maxint'" ** This code to get a decent intensity range in the graph regardless of entries Local intnumlist=subinstr("`intenlist'"," ",", ".) // a numlist with commas Local colorlist "ebblue eltblue orange orange_red red uwred purple" * uwred is a color I created and saved in my personal ado file ![]() * edits code so colors now print in the order of colorlist * uses syntax "scatter y1 y2 x" to print two-line labels * calculates and prints RGB values as well as color names style file for named color and identifies RGB code * Stata program to generate color swatches I also tested creating my own color (uwred) and saving it in a. But I wanted to see ranges of colors using the intensity values across several different named colors. The ado file full_palette generates a swatch of the 66 named colors in Stata, with their RGB values (you can access this by typing help full_palette and installing the ado), and the built-in ado palette color will show color samples and the RGB values for two colors (type help palette color to see the syntax of the command). Numbers less than 1 lighten the color and numbers greater than 1 darken the color. Named colors can be modified with the syntax “color*#. Color Swatch GeneratorĪlthough Stata can generate colors using any set of RGB values, for a variety of reasons* I found it easiest to work with the built-in named colors. Pro tip: remember to reset the plot macro to ” ” (empty) (or use a new macro name each time) or you will get unpleasant results with repeated graphs. In this code, each line gets added to the macro plotlist. Local plotlist "`plotlist' (code_for_one_line )" Trick 2 is to use Stata macros to generate the lines of a plot. Or self-labeling scatterplots by having a label for all values. Trick 1 that I have learned is to generate self-labeling lines by creating a variable that has the label only in the last value of the x-axis variable, year in my case. UPDATED to include RGB values in the color palette and to give the formulas for calculating them from intensities. ![]() Everybody else may wish to give it a pass. This is a “stats nerd” post that assumes the reader uses Stata, a statistical package. A few readers may be interested in how I used Stata to create the color scheme for the offenses in the graphs I’ve posted recently. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |