**Lecture 5: Visualizing data cd "/Users/crystal/Box/_Biostat212_2021/Week5/Lecture" use data/acupuncture.dta, clear /*HISTOGRAMS*/ * Create a histogram of health_bl histogram health_bl //density on yaxis histogram health_bl, freq //frequency on y axis /*note that the shape of the graph is similar*/ * Create a bar chart showing the mean of health_bl for the treatment vs. control groups graph bar (mean) health_bl, over(group) /*BOXPLOT*/ * Create a box plot for health_bl by group graph box health_bl, over(group) * Create a box plot for health_bl by sex and group graph box health_bl, over(sex) over(group) /*DOTPLOT*/ * Create a dot plot comparing f1, f2, and f5 dotplot f1 f2 f5 /*SCATTER PLOTS WITH FITTED LINES*/ * Create a 2-way scatterplot of health_bl and basehs with a lowess line twoway scatter basehs health_bl || /// lowess basehs health_bl * Create a 2-way scatterplot of health_bl and basehs with a lowess and linear fit line twoway scatter basehs health_bl || /// lowess basehs health_bl || /// lfit basehs health_bl /*EXPORTING GRAPHS WITH PUTDOC*/ * Export a graphic as a *.png file (keep graph window open!) graph export "output/scatter_basehs_healthbl.png", replace //or could use graph export "scatter_basehs_healthbl", as(png) /*make sure your graph window from last command (line 38-40) is still open*/ * Put the graphic into a Word document with putdocx putdocx clear putdocx begin putdocx paragraph, halign(center) putdocx image "output/scatter_basehs_healthbl.png" putdocx save "output/lecture_5_image", replace **************************************************************************** *Figure 1 twoway /// scatter posths acuptreatments if migraine==0 /// , msize(small) mcolor(black) || /// lfit posths acuptreatments if migraine==0 /// , lcolor(purple) || /// scatter posths acuptreatments if migraine==1 /// , msize(small) mcolor(red) || /// lfit posths acuptreatments if migraine==1 /// , lcolor(green) || /// , title (Figure 1) /// note () /// ytitle(PSH) /// xtitle(# acu) /// scheme(s2color) /// legend(order(2 "No migraine" 4 "Migraine")) /// saving("output/figure1.gph", replace) **************************************************************************** *Figure 2 twoway /// kdensity posths if no_acu==0 /// , lcolor(black) || /// kdensity posths if no_acu==1 /// , lcolor(black) || /// , yscale(on) /// graphregion(fcolor(stone) lcolor(none)) /// legend(order(1 "1 or more acupuncture treatments" /// 2 "No acupuncture treatments")size(medium)) /// ytitle("Density") /// xtitle("Post-study headache score") /// title(Figure 2: Distribution of headache score) /// saving("output/figure2.gph", replace)