Last active
February 25, 2024 03:28
-
-
Save isaacgeng/630f0147f084a9efc0a69d09f98fba6b to your computer and use it in GitHub Desktop.
Bar plot with custom bar label
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see https://www.statalist.org/forums/forum/general-stata-discussion/general/33124-adding-other-data-as-a-label-to-bar-graph | |
sysuse census, clear | |
collapse (sum) pop pop5_17, by(region) | |
generate pr_5_17 = round(pop5_17/pop, 0.01)*100 | |
replace pop = pop/1000000 | |
rename pop pop_millions | |
graph bar (asis) pop_millions, over(region) ytitle("Population (In Millions)") blabel(bar) | |
local nb=`.Graph.plotregion1.barlabels.arrnels' | |
forval i=1/`nb' { | |
.Graph.plotregion1.barlabels[`i'].text[1]=`"`=string(`=pr_5_17[`i']',"%6.1f")'% of `=string(`=pop_mil[`i']',"%6.1f")'mln"' | |
} | |
.Graph.drawgraph |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment