Hi all,
I'm using Stata 13.1. I am trying to present my bar chart using twoway bar and then specifying -horizontal-. As there are only two categories in my data, I want to control the width of my bars so they look nicer aesthetically. However, when I specify the barwidth, I get a rather large gap between the two bars. I though -graph display- my offer some joy in reducing the gap between the two bars, but I havent because it changes the aspect so that the font is very small. Also -bargap- (bargap(0)) appears to have no effect on the graph.
Another problem I seem to encounter is that I wish to remove the -xlabel- values from being presented (the main reason is that I am addiing the values at the end of each bar and so dont want to duplicate). However when I add -xla(none)-, I lose the bar of the bottom category. I've pasted too sets of code below - please note that the code includes use of -splitvallabels- (findit splitvallabels).
Any help appreciated.
*************BEGIN CODE
clear
#delimt ;
set seed 339487731
set obs 1
g VNuAF_Strokes = floor(runiform() *100)
g VNuAF_Strokes_NOAC = floor(VNuAF_Strokes * 0.95)-10
g n = _n
reshape long V, i(n) j(New_var) string
g order = 2 if New_var =="NuAF_Strokes"
replace order = 1 if New_var=="NuAF_Strokes_NOAC"
sort order
label define Order 2 "AF strokes in 2014/15:" 1 "AF strokes not on anticoagulation:"
label values order Order
gen V2 = V[2]
gen V1 = V[1]
list
format %9.0gc V*
gen mytext = ""
qui forval j = 1/2 {
summarize V`j' , meanonly
replace mytext = string(r(max), "%9.0gc") in `j'
}
splitvallabels order, length(18) nob local(foo)
su V, meanonly
g a = `r(max)'
#delim ;
twoway bar V order if order == 2, horiz barw(0.2) bcolor("91 53 140") ||
bar V order if order == 1, horiz barw(0.2) bcolor("0 148 218")
legend(off) ysc(lc(none)) xsc(lc(none)) bargap(0)
yla(`foo' , val noticks ang(h)) xla(0 (20) 100, format(%9.0gc) ang(h))
ytitle("") xtitle("") plotregion(color(white)) ||
sc order a, mlabel(mytext) mlabcolor(black) msymbol(i) mlabsize(medium) ;
#delim cr
******************MISSING BAR FOLLOWING -xla(none)-
clear
#delimt ;
set seed 339487731
set obs 1
g VNuAF_Strokes = floor(runiform() *100)
g VNuAF_Strokes_NOAC = floor(VNuAF_Strokes * 0.95)-10
g n = _n
reshape long V, i(n) j(New_var) string
g order = 2 if New_var =="NuAF_Strokes"
replace order = 1 if New_var=="NuAF_Strokes_NOAC"
sort order
label define Order 2 "AF strokes in 2014/15:" 1 "AF strokes not on anticoagulation:"
label values order Order
gen V2 = V[2]
gen V1 = V[1]
list
format %9.0gc V*
gen mytext = ""
qui forval j = 1/2 {
summarize V`j' , meanonly
replace mytext = string(r(max), "%9.0gc") in `j'
}
splitvallabels order, length(18) nob local(foo)
su V, meanonly
g a = `r(max)'
#delim ;
twoway bar V order if order == 2, horiz barw(0.2) bcolor("91 53 140") ||
bar V order if order == 1, horiz barw(0.2) bcolor("0 148 218")
legend(off) ysc(lc(none)) xsc(lc(none)) bargap(0)
yla(`foo' , val noticks ang(h)) xla(none)
ytitle("") xtitle("") plotregion(color(white)) ||
sc order a, mlabel(mytext) mlabcolor(black) msymbol(i) mlabsize(medium) ;
#delim cr
I'm using Stata 13.1. I am trying to present my bar chart using twoway bar and then specifying -horizontal-. As there are only two categories in my data, I want to control the width of my bars so they look nicer aesthetically. However, when I specify the barwidth, I get a rather large gap between the two bars. I though -graph display- my offer some joy in reducing the gap between the two bars, but I havent because it changes the aspect so that the font is very small. Also -bargap- (bargap(0)) appears to have no effect on the graph.
Another problem I seem to encounter is that I wish to remove the -xlabel- values from being presented (the main reason is that I am addiing the values at the end of each bar and so dont want to duplicate). However when I add -xla(none)-, I lose the bar of the bottom category. I've pasted too sets of code below - please note that the code includes use of -splitvallabels- (findit splitvallabels).
Any help appreciated.
*************BEGIN CODE
clear
#delimt ;
set seed 339487731
set obs 1
g VNuAF_Strokes = floor(runiform() *100)
g VNuAF_Strokes_NOAC = floor(VNuAF_Strokes * 0.95)-10
g n = _n
reshape long V, i(n) j(New_var) string
g order = 2 if New_var =="NuAF_Strokes"
replace order = 1 if New_var=="NuAF_Strokes_NOAC"
sort order
label define Order 2 "AF strokes in 2014/15:" 1 "AF strokes not on anticoagulation:"
label values order Order
gen V2 = V[2]
gen V1 = V[1]
list
format %9.0gc V*
gen mytext = ""
qui forval j = 1/2 {
summarize V`j' , meanonly
replace mytext = string(r(max), "%9.0gc") in `j'
}
splitvallabels order, length(18) nob local(foo)
su V, meanonly
g a = `r(max)'
#delim ;
twoway bar V order if order == 2, horiz barw(0.2) bcolor("91 53 140") ||
bar V order if order == 1, horiz barw(0.2) bcolor("0 148 218")
legend(off) ysc(lc(none)) xsc(lc(none)) bargap(0)
yla(`foo' , val noticks ang(h)) xla(0 (20) 100, format(%9.0gc) ang(h))
ytitle("") xtitle("") plotregion(color(white)) ||
sc order a, mlabel(mytext) mlabcolor(black) msymbol(i) mlabsize(medium) ;
#delim cr
******************MISSING BAR FOLLOWING -xla(none)-
clear
#delimt ;
set seed 339487731
set obs 1
g VNuAF_Strokes = floor(runiform() *100)
g VNuAF_Strokes_NOAC = floor(VNuAF_Strokes * 0.95)-10
g n = _n
reshape long V, i(n) j(New_var) string
g order = 2 if New_var =="NuAF_Strokes"
replace order = 1 if New_var=="NuAF_Strokes_NOAC"
sort order
label define Order 2 "AF strokes in 2014/15:" 1 "AF strokes not on anticoagulation:"
label values order Order
gen V2 = V[2]
gen V1 = V[1]
list
format %9.0gc V*
gen mytext = ""
qui forval j = 1/2 {
summarize V`j' , meanonly
replace mytext = string(r(max), "%9.0gc") in `j'
}
splitvallabels order, length(18) nob local(foo)
su V, meanonly
g a = `r(max)'
#delim ;
twoway bar V order if order == 2, horiz barw(0.2) bcolor("91 53 140") ||
bar V order if order == 1, horiz barw(0.2) bcolor("0 148 218")
legend(off) ysc(lc(none)) xsc(lc(none)) bargap(0)
yla(`foo' , val noticks ang(h)) xla(none)
ytitle("") xtitle("") plotregion(color(white)) ||
sc order a, mlabel(mytext) mlabcolor(black) msymbol(i) mlabsize(medium) ;
#delim cr

Comment