Hello!
I am trying to display data at two time points, using box plots combined with a scatter plot in which each individual's data at time 1 is connected to their data at time 2.
Having searched around, I'm fine with the box plots and the scatter plots, but cannot connect each pair of dots.
I've illustrated below with bplong.
The problem is there is only one line, apparently connecting the means at the two time points?.
I've seen xtline referred to but don't understand how to utilize that.
Thanks for any guidance!
Tim
Here's the code:
sysuse bplong
drop if patient > 10 // only need small n to illustrate
sort when
* Generate parameters for box plot
by when: egen med = median(bp)
by when: egen lqt = pctile(bp), p(25)
by when: egen uqt = pctile(bp), p(75)
* generate graph
twoway rbar lqt med when, barw(.5) fcolor(gs12) lcolor(black) || ///
rbar med uqt when, barw(.5) fcolor(gs12) lcolor(black) || ///
scatter bp when, graphregion(fcolor(gs15)) mcolor(black) msymbol(o) msize(small) ///
connect(l) ///
legend(off) xlabel( 1 "Before" 2 "After") ///
ytitle(BP)
Here's the result:
I am trying to display data at two time points, using box plots combined with a scatter plot in which each individual's data at time 1 is connected to their data at time 2.
Having searched around, I'm fine with the box plots and the scatter plots, but cannot connect each pair of dots.
I've illustrated below with bplong.
The problem is there is only one line, apparently connecting the means at the two time points?.
I've seen xtline referred to but don't understand how to utilize that.
Thanks for any guidance!
Tim
Here's the code:
sysuse bplong
drop if patient > 10 // only need small n to illustrate
sort when
* Generate parameters for box plot
by when: egen med = median(bp)
by when: egen lqt = pctile(bp), p(25)
by when: egen uqt = pctile(bp), p(75)
* generate graph
twoway rbar lqt med when, barw(.5) fcolor(gs12) lcolor(black) || ///
rbar med uqt when, barw(.5) fcolor(gs12) lcolor(black) || ///
scatter bp when, graphregion(fcolor(gs15)) mcolor(black) msymbol(o) msize(small) ///
connect(l) ///
legend(off) xlabel( 1 "Before" 2 "After") ///
ytitle(BP)
Here's the result:
Comment