I was asked off-forum by someone in the medical field if I knew of how to create the graphic below.
The following is a naive approach using twoway. With some effort, much of the code can be generalized if the intention is to produce many such graphs. It is not difficult to read the data from the graph. The number of patients is a continuous variable and one will often use an indicator for the presence of a symptom. So here is the data reconstructed and code.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(patid patients myalgia fatigue sob cough fever) 1 60 0 1 1 1 1 2 52 1 1 1 1 1 3 39 0 0 1 1 1 4 21 0 0 0 1 1 5 14 0 1 0 1 1 6 14 1 0 1 1 1 7 13 0 0 1 0 1 8 12 0 1 1 0 1 9 10 1 1 0 1 1 10 8 0 0 1 0 0 11 8 0 1 1 1 0 12 8 0 0 0 0 1 13 7 0 0 1 1 0 14 7 0 1 0 0 1 15 7 1 1 1 0 1 16 6 0 1 0 0 0 17 6 0 1 1 0 0 18 6 1 1 1 1 0 19 5 1 0 1 1 0 20 4 1 0 0 1 1 21 3 1 1 0 0 0 22 3 0 1 0 1 0 23 3 1 0 1 0 1 24 2 1 0 1 0 0 25 2 0 0 0 1 0 26 1 1 1 1 0 0 27 1 1 0 0 1 0 28 1 1 0 0 0 1 29 1 1 1 0 0 1 end local i 1 foreach var of varlist myalgia - fever{ gen N`var'= sum(`var'*patients) replace N`var'= (N`var'[_N]) replace `var'= cond(`var'>0, -`i'+0.5, .) local ++i } forval var= 1/`=`i'-1'{ gen m`var'=-`var'+0.5 } egen min= rowmin(myalgia-fever) egen max= rowmax(myalgia-fever) tab min, gen(min) gen patients2= patients/5 tw (bar patients2 patid, barw(0.7) bcolor(navy)) /// (scatter patients2 patid, mc(none) mlab(patients) mlabc(navy) mlabs(vsmall) mlabp(12) ) /// (scatter m1-m5 patid, mcolor(gray%20 gray%20 gray%20 gray%20 gray%20) /// msize(medium medium medium medium medium) graphregion(color(white))) /// (scatter myalgia-fever patid, mcolor(black black black black black) leg(off) /// msize(medium medium medium medium medium) xlab("") /// xtitle("") yscale(lstyle(none)) xscale(lstyle(none)) ylab("" noticks)) /// (dropline max patid if min1, base(-4.5) mcolor(none) lcolor(black) lwidth(thick)) /// (dropline max patid if min2, base(-3.5) mcolor(none) lcolor(black) lwidth(thick)) /// (dropline max patid if min3, base(-2.5) mcolor(none) lcolor(black) lwidth(thick)) /// (dropline max patid if min4, base(-1.5) mcolor(none) lcolor(black) lwidth(thick) /// text(-0.5 -3.5 "Myalgia", size(vsmall)) text(-1.5 -3.5 "Fatigue/ Malaise", size(vsmall)) /// text(-2.5 -3.5 "Shortness of breath", size(vsmall)) /// text(-3.5 -3.5 "Cough", size(vsmall)) text(-4.5 -3.5 "Fever", size(vsmall))) /// (scatteri -0.5 `=(-Nmyalgia[1]/30)-8' -0.5 -8 , recast(line) lw(vvthick) lc(navy)) /// (scatteri -1.5 `=(-Nfatigue[1]/30)-8' -1.5 -8 , recast(line) lw(vvthick) lc(navy)) /// (scatteri -2.5 `=(-Nsob[1]/30)-8' -2.5 -8 , recast(line) lw(vvthick) lc(navy)) /// (scatteri -3.5 `=(-Ncough[1]/30)-8' -3.5 -8 , recast(line) lw(vvthick) lc(navy)) /// (scatteri -4.5 `=(-Nfever[1]/30)-8' -4.5 -8 , recast(line) lw(vvthick) lc(navy)) /// (scatteri -0.15 0 14 0, recast(line) lw(medium) lc(black)) /// (scatteri -0.05 0 -0.05 30, recast(line) lw(medium) lc(black)) /// (scatteri -5 `=(-Nfever[1]/30)-8.5' -5 -7.5, recast(line) lw(medium) lc(black) /// text(0 -0.5 "0-", size(small)) text(4 -0.8 "20-", size(small)) /// text(8 -0.8 "40-", size(small)) text(12 -0.8 "60-", size(small)) /// text(7 -7 "Number of Patients", orient(vert) size(small)) /// text(-5.45 -7.9 "0", size(vsmall)) text(-5.1 -8 "-", orient(vert) size(vsmall)) /// text(-5.1 `=(((-Nmyalgia[1]/30)/Nmyalgia[1])*100)-8' "-", orient(vert) size(vsmall)) /// text(-5.45 `=(((-Nmyalgia[1]/30)/Nmyalgia[1])*100)-7.9' "100", size(vsmall)) /// text(-5.1 `=(((-Nmyalgia[1]/30)/Nmyalgia[1])*200)-8' "-", orient(vert) size(vsmall)) /// text(-5.45 `=(((-Nmyalgia[1]/30)/Nmyalgia[1])*200)-7.9' "200", size(vsmall)) /// text(-5.9 `=(((-Nmyalgia[1]/30)/Nmyalgia[1])*125)-7.9' "Number of Patients", size(vsmall)))
Comment