Announcement

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

  • Re-organize bar graph variables

    Hi everyone, I have a problem that's wrinkling my brain. Is it possible to group all the bars of the same color and swap the variables in the x-axis with those in the legend? So that each cluster of bars on the x-axis are my facility domains (v1-4: Facility Capacity, Learning Environment, Infrastructure, Self Assessment) and the coloring is sorted by Hospital # (1-6)?
    Click image for larger version

Name:	Screen Shot 2023-02-23 at 3.16.22 PM.png
Views:	1
Size:	938.6 KB
ID:	1703068


    Code:
    graph bar (mean) v1 (mean) v2 (mean) v3 (mean) v4,  over(Hospital)

    Do I have to switch the way my variables are set up or is there a way to recode the graph command? Thanks!
    Last edited by Alex Melown; 23 Feb 2023, 06:36.

  • #2
    No data example here, but you can run this script to see some technique that may help. You need to install statplot from SSC before you can use it.

    Code:
    clear
    set scheme s1color
    set seed 31459265
    set obs 100
    forval j = 1/4 {
        gen v`j' = runiformint(1,5)
    }
    
    gen hospital = ceil(_n/20)
    
    graph bar (mean) v1-v4 , over(hospital) name(G1, replace)
    
    ssc inst statplot
    statplot v1-v4, over(hospital) name(G2, replace) recast(bar) asyvars

    Comment

    Working...
    X