Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bar charts: Percent on y-axis, absolute count over each bar?

    Hi,

    I'm making a bunch of barcharts, some using graph, some using catplot, like this:

    Code:
    graph bar, over(Population_categories_j, relabel(`r(relabel)')) blabel(total, format(%9.1f)) name(Population_record) ylabel(0(10)80) ytitle("Percent") xsize(4)
    and this

    Code:
    catplot combined combined_group, asyvars vertical blabel(total, format(%9.1f)) percent(combined) ylabel(0(10)80) name(combined_bar_chart) ytitle("Percent")
    As you can see, I have figured out how to show percentages on the columns. Is it possible to keep showing percentages on the y-axis while showing the absolute number associated with each bar above the bar, instead of the percentage which is currently shown? Thank you!
    Last edited by Andreas Moegelmose; 20 Mar 2019, 00:53.

  • #2
    Data example please. https://www.statalist.org/forums/help#stata

    (The same section gives a request to identify community-contributed commands as such, here catplot from SSC.)

    Comment


    • #3
      graph bar does not allow flexibility to define your own bar labels. The only way you achieve this is to use the text() option. Otherwise, it is easier to switch to twoway bar. For purposes of illustration, I partly illustrate the former.

      Code:
      sysuse auto
      *PICK OUT TOTAL VALUES FROM GRAPH (here, 3rd bar = 6429.23)
      graph bar price, over(rep78) xsize(4) blabel(total) bar(1, bcolor(none)) scheme(s1color)
      *USE TEXT OPTION TO ASSIGN BAR LABEL
      graph bar (percent) price, over(rep78) ylab(0(10)45) ytitle("Percent") xsize(4) ///
      text(45 50 "6429.23", size(small)) bar(1, bcolor(none))scheme(s1color)
      Click image for larger version

Name:	Graph1.png
Views:	1
Size:	20.6 KB
ID:	1489096

      Click image for larger version

Name:	Graph2.png
Views:	1
Size:	15.6 KB
ID:	1489097

      Comment

      Working...
      X