Hi everyone,
I'm creating a sort of box plot using twoway graphs but I don't know how to add lines indicating if there's a significant difference between my groups. See picture below. The horizontal square brackets and asterisks (indicating differences between group 1 vs group 2-5) in the picture were added using powerpoint which isn't really optimal. Does anyone know how to do this within Stata?
The variables I'm looking at are on a continuous scale with 20-200 observations per group. I'm using the Stata command ranksum to estimate differences between groups. My code and a fake example of my data is below.
I'm using Stata v16.1 (on Mac).
Many thanks!
Gunnar
.
Fake example of my data
clear
input float(Group Protein_1)
1 123
1 245
1 1044
1 334
1 535
1 355
1 455
2 355
2 354
2 432
2 132
2 82
end
I'm creating a sort of box plot using twoway graphs but I don't know how to add lines indicating if there's a significant difference between my groups. See picture below. The horizontal square brackets and asterisks (indicating differences between group 1 vs group 2-5) in the picture were added using powerpoint which isn't really optimal. Does anyone know how to do this within Stata?
The variables I'm looking at are on a continuous scale with 20-200 observations per group. I'm using the Stata command ranksum to estimate differences between groups. My code and a fake example of my data is below.
I'm using Stata v16.1 (on Mac).
Many thanks!
Gunnar
.
Code:
sort Group by Group: egen med = median(Protein_1) by Group: egen lqt = pctile(Protein_1), p(25) by Group: egen uqt = pctile(Protein_1), p(75) twoway (rbar lqt med Group if Group==1, barw(.5) fcolor(red) lcolor(black) ) /// (rbar lqt med Group if Group==2, barw(.5) fcolor(midgreen) lcolor(black) ) /// (rbar lqt med Group if Group==3, barw(.5) fcolor(orange) lcolor(black) ) /// (rbar lqt med Group if Group==4, barw(.5) fcolor(olive_teal) lcolor(black) ) /// (rbar lqt med Group if Group==5, barw(.5) fcolor(midblue) lcolor(black) ) || /// (rbar med uqt Group if Group==1, barw(.5) fcolor(red) lcolor(black) ) /// (rbar med uqt Group if Group==2, barw(.5) fcolor(midgreen) lcolor(black) ) /// (rbar med uqt Group if Group==3, barw(.5) fcolor(orange) lcolor(black) ) /// (rbar med uqt Group if Group==4, barw(.5) fcolor(olive_teal) lcolor(black) ) /// (rbar med uqt Group if Group==5, barw(.5) fcolor(midblue) lcolor(black) ) || /// (scatter Protein_1 Group if diagnosis3==1, graphregion(fcolor(gs15)) mfcolor(red) mlcolor(black) msymbol(o) legend(off)) /// (scatter Protein_1 Group if diagnosis3==2, graphregion(fcolor(gs15)) mfcolor(midgreen) mlcolor(black) msymbol(o) legend(off)) /// (scatter Protein_1 Group if diagnosis3==3, graphregion(fcolor(gs15)) mfcolor(orange) mlcolor(black) msymbol(o) legend(off)) /// (scatter Protein_1 Group if diagnosis3==4, graphregion(fcolor(gs15)) mfcolor(olive_teal) mlcolor(black) msymbol(o) legend(off)) /// (scatter Protein_1 Group if diagnosis3==5, graphregion(fcolor(gs15)) mfcolor(midblue) mlcolor(black) msymbol(o) legend(off)), /// xlabel(1 "Group 1" 2 "Group 2" 3 "Group 3" 4 "Group 4" 5 "Group 5", labsize(small)) /// xtitle("") /// ytitle("") /// yscale(log range(50 22000)) /// ylabel(1000 "100" 10000 "1,000" 100000 "10,000", labsize(vsmall) angle(horizontal) grid gmin gmax) /// graphregion(color(white)) /// ysize(7) xsize(5) /// title("A. Protein 1", position(11) size(medlarge))
Fake example of my data
clear
input float(Group Protein_1)
1 123
1 245
1 1044
1 334
1 535
1 355
1 455
2 355
2 354
2 432
2 132
2 82
end
Comment