Dear Statalisters,
I am trying to plot a number of separate connected scatter plots and on top of these I am superimposing multiple horizontal lines. The code below works:
However, I am clearly missing a trick in terms of nested foreach loops to run through Mucosal ID and Dilution. I could not figure out how to make these work in the context of a two-way plot.
Additionally, is there a clever way to modify the colour per one of the foreach loops - or would this require a further nested foreach loop.
Thanks in advance
Best wishes
Robert
I am trying to plot a number of separate connected scatter plots and on top of these I am superimposing multiple horizontal lines. The code below works:
Code:
levelsof Assay2, local(levels) foreach var of local levels { graph twoway scatter Mean Concentration if USBC=="S" & n1==1 & Assay2=="`var'", title("`var'") msymbol(X) connect(l) legend(off)|| /// line Mean Concentration if Dilution==25 & MucosalID==1 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==2 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==3 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==4 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==5 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==6 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==7 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==8 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==25 & MucosalID==9 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==50 & MucosalID==1 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==2 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==3 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==4 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==5 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==6 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==7 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==8 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==50 & MucosalID==9 & Assay2=="`var'", lcolor(blue) || /// line Mean Concentration if Dilution==100 & MucosalID==1 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==2 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==3 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==4 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==5 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==6 & Assay2=="`var'", lcolor(green) || /// line Mean Concentration if Dilution==100 & MucosalID==7 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==8 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==100 & MucosalID==9 & Assay2=="`var'", lcolor(orange) || /// line Mean Concentration if Dilution==200 & MucosalID==1 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==2 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==3 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==4 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==5 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==6 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==7 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==8 & Assay2=="`var'", lcolor(red) || /// line Mean Concentration if Dilution==200 & MucosalID==9 & Assay2=="`var'", lcolor(red) graph export "/Users/rob/Documents/OVG/Lab work/SC_`var'.jpg", replace }
Additionally, is there a clever way to modify the colour per one of the foreach loops - or would this require a further nested foreach loop.
Thanks in advance
Best wishes
Robert
Comment