Announcement

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

  • Change Y axis for bar chart

    Hi all,

    I am trying to make a simple bar chart. All of my means are very close together, between 3.2 and 2.9, and I'm hoping to get my ticks on my Y axis to change --right now it's showing 0 through 3, with the 3.2 going above. A range of 2 through 4 might be a little better, or even 2.5 to 3.5, or something like that. Here's the current code I'm working with:

    Code:
     graph bar (mean) flu, over(visit) blabel(bar) ytitle(flu) ylabel(#3) title(Mean flu by visitation level)
    EDIT: I have tried adding in ylabel(2.5(0.25)3.5) but the axis still starts at 0, is there a way to override that?
    Last edited by Taylor Walter; 14 Dec 2018, 10:19.

  • #2
    it's always true throughout Stata graphics that axis label options will never lead to shortened axes (or omitted data).

    That said, the main issue here is a Stata view, which I share in this case, that bars should start at 0 -- and which you have to fight against if you want something different.

    What's the point of the bar (which encodes a length to indicate magnitude) if you're encoding instead (magnitude MINUS arbitrary constant)?

    I recommend instead graph dot, indeed I recommend showing much, much more of your data than just the means. If you post your data, or a sample of them, I will happily make concrete suggestions (modulo being awake at the time).

    If someone is telling you to do this, it's still a bad idea. There are work-arounds, and this will sound sniffy if not patronising, but I won't suggest code to implement what I think is unsound statistically and graphically.

    Comment


    • #3
      Sure, here is some sample data. Essentially, different types of visits are the visit variables, and people ranked their frequency on a scale of 1 to 5, and also ranked the severity of their most recent flu on a scale of 1-5--pretty straightforward, hopefully.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double flu byte(visit visit1 visit2 visit3 visit4)
      3.4800000190734863 1 1 1 1 1
       3.569999933242798 1 1 1 1 1
       3.690000057220459 2 1 1 5 4
       3.049999952316284 1 1 1 3 1
      3.0399999618530273 1 1 1 2 2
       3.450000047683716 5 4 1 1 3
      3.0899999141693115 5 5 1 1 1
       3.490000009536743 5 1 1 1 5
                       3 5 4 1 1 1
      3.3399999141693115 5 5 2 5 5
                       3 5 3 1 1 1
       2.009999990463257 4 1 1 1 1
      2.0799999237060547 1 1 1 1 3
       3.049999952316284 1 1 1 1 3
      3.0299999713897705 1 1 1 1 1
      3.8499999046325684 1 1 5 1 1
      2.0899999141693115 4 5 1 3 3
       3.059999942779541 5 3 1 4 4
                    3.25 1 4 1 8 5
      3.0299999713897705 3 2 1 4 4
      3.4100000858306885 5 3 1 1 1
                       3 5 4 4 3 1
      3.4700000286102295 2 4 4 1 1
      3.7100000381469727 4 1 1 1 1
      2.0399999618530273 4 1 1 1 4
      3.2100000381469727 5 3 1 1 4
      end
      ------------------ copy up to and including the previous line ------------------

      Comment


      • #4
        Thanks for the example. Here is one of several possibilities. It looks odd because you have given a small sample and even smaller subsets (down to 1 observation). And it's certainly indicative, not definitive.

        The idea is to show all the data, boxes for medians and quartiles (here with whiskers to 5 and 95 percentiles, except that Stata uses the extremes with these sample sizes), and reference lines for the means.

        Code:
        stripplot flu, over(visit) vertical box(barw(0.1)) boffset(-0.15) pctile(5) ///
        refline cumul cumprob height(0.4) yla(, ang(h)) ytitle(, orient(horiz))
        Click image for larger version

Name:	flu.png
Views:	1
Size:	20.6 KB
ID:	1474935


        stripplot is from SSC and must be installed before you can use it. You can also plot confidence interval bars, which look very silly in this case, but should make much more sense for your full dataset.

        Using stripplot as a search term in this forum should uncover several other examples.

        Comment


        • #5
          This is excellent, I wasn't aware of stripplot. Thank you very much!

          Comment

          Working...
          X