![]() ![]() For example:įunction y = x^3, range(-2 2) lpattern(-) || ///įunction y = x^4, range(-2 2) lpattern(.-) ///Ĭols(3) pos(5) ring(0) region(lcolor(none)))īut suppose you prefer to use marker symbols rather than line patterns to differentiate the line plots, how can you specify this option? Use the recast option (-help advanced_options-): These options are particularly helpful when you have many functions to plot. Tw function y = 4*x^2, range(-2 2) lcolor(red) lwidth(medthick) lpattern(-) ![]() For example, if you want to change the color, width, and pattern of the line use lcolor, lwidth, and lpattern options: It is easy to change the line attributes of the plot. If you want to draw the other side of the parabola or change the range, you can specify the range as follows: The default is that the function is drawn over the range. For example, the half of a parabola with the equation y = x^2 can be drawn by typing: Graph export combined_dbp_sbp_ba.Stata's -graph twoway function- draws the line plot of a specified function. ![]() Graph save combined_dbp_sbp_ba.gph, replace // Ycommon /// so the y axes are on the same scaleī1title("Average of IBP and Standard (mmHg)") /// Graph combine 1_sbp_bland_altman_ave.gph pictures/2_dbp_bland_altman_ave.gph, /// Graph export 2_dbp_bland_altman_ave.png, width(4000) replace Graph save 2_dbp_bland_altman_ave.gph, replace Yline($lowerCL1, lpattern(dash) lcolor(gray)) /// Yline($mean1, lpattern(shortdash) lcolor(gray)) /// Graph twoway scatter diff_dbp_ave mean_dbp_ave, /// Gen diff_dbp_ave=ibp_dbp_pair-average_dbp_omron_23 Gen mean_dbp_ave=(average_dbp_omron_23+ibp_dbp_pair)/2 Graph export 1_sbp_bland_altman_ave.png, width(4000) replace Graph save 1_sbp_bland_altman_ave.gph, replace Graphregion(color(white)) ylabel(, grid glcolor(gs14)) /// white backgroundĪspectratio(1.08) // annoyingly, this wasn't a perfectly square figure so this line fixes it. Yline($upperCL1, lpattern(dash) lcolor(gray)) /// Yline($lowerCL1, lpattern(dash) lcolor(gray)) /// ditto Yline($mean1, lpattern(shortdash) lcolor(gray)) /// calls the macro from above Xtitle("") /// xtitle("Average of Reference and Comparator (mmHg)") Ytitle("") /// ytitle("Reference Minus Comparator (mmHg)") Graph twoway scatter diff_sbp_ave mean_sbp_ave, /// Global lowerCL1=r(mean) - 2*r(sd) // this saves a macro for the mean+2 times the SD ("r(sd)") Global mean1=r(mean) // this saves the macro as mean1, to be called later Sum diff_sbp_ave // this allows you to make a macro of the mean ("r(mean)") of the y axis variable Gen diff_sbp_ave=ibp_sbp_pair-average_sbp_omron_23 // this will be y-axis Gen mean_sbp_ave=(average_sbp_omron_23+ibp_sbp_pair)/2 // this will be the x-axis Graph export combined_scatterplots_fit.png, width(4000) replace Graph save combined_scatterplots_fit.gph, replace // Graph combine 20_sbp_scatterplot_fit.gph 21_dbp_scatterplot_fit.gph, /// Graph export 21_dbp_scatterplot_fit.png, width(4000) replace Graph save 21_dbp_scatterplot_fit.gph, replace Graphregion(color(white)) ylabel(, grid glcolor(gs14)) /// Yline(90, lpattern(solid) lcolor(gray)) /// Xline(90, lpattern(solid) lcolor(gray)) /// (scatter ibp_dbp_pair average_dbp_omron_23, mcolor(black) msize(vsmall)), /// (function y=x, ra(average_dbp_omron_23) clcolor(gs4)) /// Twoway (lfit ibp_dbp_pair average_dbp_omron_23, lcolor(gray) lpattern(dash) lwidth(vthick)) /// Graph export 20_sbp_scatterplot_fit.png, width(4000) replace Graph save 20_sbp_scatterplot_fit.gph, replace // need graph to merge later Xlabel(90(20)170) ylabel(90(20)170) /// where X and Y labels occurĪspectratio(1) // force figure to be a 1x1 square, not a rectangle Graphregion(color(white)) ylabel(, grid glcolor(gs14)) /// white background, light gray lines Yline(140, lpattern(solid) lcolor(gray)) /// ditto Xline(140, lpattern(solid) lcolor(gray)) /// cutoff for systolic hypertension Ytitle("") /// no title, will add when merging SBP and DBP (scatter ibp_sbp_pair average_sbp_omron_23, mcolor(black) msize(vsmall)), /// make dots appear for scatter, y x axis (function y=x, ra(average_sbp_omron_23) clcolor(gs4)) /// diagonal line of unity Twoway (lfit ibp_sbp_pair average_sbp_omron_23, lcolor(gray) lpattern(dash) lwidth(vthick)) /// line of fit code **********scatterplot ave with lines of fit The Y-axis is the difference between the variables and the X-axis is a mean of the variables. ![]() You just need to set up all of the variables intentionally to trick it into rendering a B-A plot. The dotted line is relative mean difference, the long dashed lines are +/- 2 SD.Īs far as Stata’s graph maker is concerned, this is a scatterplot. Again, two different B-A plots that are merged then labels applied. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |