Announcement

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

  • Trying to add percentage to graph value label - I have looked at other threads....

    Hello:

    I'm trying to add a percentage sign next to value labels for the bar chart below. I know this has been discussed previously and I've read the posts. But since the threads are quite old, I'm hoping that there might be another easier way to do this. Code and graph pasted below. Thank you, Gene


    graph bar (asis) Jan21 Dec21 Sept22 if id == "polv_i", graphregion(margin(t+0 b+0)) asyvar ylabel(0(20)80) ///
    scheme(s1color) ///
    ylabel(, labsize(small)) ///
    blabel(total, size(large)) ///
    bar(1, color(gray)) bar(2, color(gray)) bar(3, color(gray)) ///
    bargap(50) ///
    legend(off) ///
    showyvars ///
    yvar(label(labsize(large))) ///
    ysize(9) xsize(16) ///
    text (77 50 "Political violence: percent who think it will increase", size(huge))




    Attached Files

  • #2
    Hello, please ignore this post. I figured it out. For those who have had same issue, someone wrote a nice bit of code here: https://gist.github.com/bbdaniels/4d...74a35d1f1516f3

    Comment


    • #3
      The link in #2 uses Graph Editor commands to fix the problem. I wouldn't want any reader, least of all Gene, to conclude that was the only or even the best way to proceed.

      The chicken and egg question here is that the data structure implied by #1 is often an awkward choice in Stata, and in any case what I think is easiest for the graph desired is to have the outcome to be plotted to be the values of a single variable.

      Given the data here and a request to plot it, I would do something like this


      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input y 
      51 
      57 
      64
      end 
      
      gen date = _n 
      label def date 1 "Jan21" 2 "Dec21" 3 "Sep22"
      label val date date 
      
      gen show = strofreal(y) + "%"
      
      twoway bar y date, barw(0.8) || scatter y date, xla(1/3, valuelabel noticks) ms(none) mla(show) mlabpos(12) mlabsize(medium) yla(0(10)70, ang(h)) legend(off) xtitle("") ytitle("") t1title(Words here)
      Click image for larger version

Name:	wanted.png
Views:	1
Size:	20.4 KB
ID:	1685386

      Comment

      Working...
      X