Announcement

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

  • Stacked bars with percentages

    Click image for larger version

Name:	Udklip.PNG
Views:	1
Size:	35.2 KB
ID:	1520375




    The image shows a graph which should allow visual comparison of the percentage of success between 3 treatments. I used the menu system and have ended up with this graph although I wish to have the bars side by side in one frame. However, as soon as I change anything, I end up with unstacked bars and/or the y axis changes to show the number of observations instead of the percentage. How can I get the three stacks of bars amounting to 100 % to be shown side by side in one graph?

    My current code is:

    graph bar, over(kolRes) asyvars stack by(, title("Success, by Treatment")) ytitle("Percentage") legend(order(1 "Success" 2 "Failure" 3 "Unknown")) by(Treatment_type)

    Bonus question: How do I get rid of the footnote about "Graphs by.."? I have tried to make its opacity 0%, but it still comes through in the .wmf file I use for export to PowerPoint.

    Thanks, Hans

    Last edited by Hans Rahr; 14 Oct 2019, 12:51.

  • #2
    Welcome to Statalist.

    If you change
    Code:
    by(Treatment_type)
    to
    Code:
    by(Treatment_type, rows(1) note(""))
    I believe it will resolve both of your concerns.

    Comment


    • #3
      It works great!
      Thank you very much
      Hans

      Comment


      • #4
        I have to say that this bar chart isn’t much of an improvement on a 3 x 3 table, which could show the frequencies as well as percentages of interest. Presumably success and failure are of most concern, but given a decision to show unknowns too, they should at least be shown clearly.

        The forum includes several posts on tabplot (Stata Journal ​​ ​​​/SSC) which could give you a hybrid graph and table.

        Comment

        Working...
        X