Announcement

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

  • how to change the scale of the y-axis in bar graph

    Hi!
    I am making a simple bar graph and the y-axis has a wider range then I would like. I have tried using yscale(range (6 8))) in various places in my command, but nothing worked
    here is the complete command.
    graph bar WB, over(EDUCATION, label(angle(60)) ) blabel(bar, format(%4.2f)) yscale(range(6(1)8))

    Thanks

  • #2
    inessa love, I guess the yaxis seems 'too long' and you want to narrow it. However, it is put clearly in Stata help files that: range() never narrows the scale of an axis or causes data to be omitted from the plot. If you wanted to graph yvar versus xvar for the subset of xvar values between 10 and 50, typing
    Code:
    scatter yvar xvar, xsc(r(10 50))
    would not suffice. You need to type
    Code:
    scatter yvar xvar if xvar>=10 & xvar<=50
    see https://www.stata.com/help.cgi?axis_scale_options

    Comment


    • #3
      It sounds as if your response varies over a narrow range and that you don't want to show zero. These are precisely the circumstances in which a bar chart with arbitrarily truncated bars is a bad idea and a dot chart is a better idea. Also, putting text at an angle is a tell-tale sign that you are struggling with long labels. By default dot charts are horizontal any way, which solves that problem too.

      You don't give a data example or show your graph so far, but a good start might be something like

      Code:
      graph dot WB, over(EDUCATION ) blabel(bar, format(%4.2f)) exclude0 yscale(range(6 8))
      Here I use the auto data as a sandbox and show some possibilities. The code is deceitful insofar as I usually build up each command step by step rather than write down commands like this all at once.

      Code:
      sysuse auto, clear
      set scheme s1color
      
      graph dot (asis) mpg if foreign, over(make, sort(1)) exclude0 blabel(bar) ///
      linetype(line) lines(lc(gs14) lw(vvthin)) yla(none) ysc(alt r(12 43))     ///
      marker(1, ms(Oh)) name(IL11)
      
      graph dot (asis) mpg if foreign, over(make, sort(1)) exclude0 blabel(bar, size(medsmall)) ///
      linetype(line) lines(lc(gs14) lw(vvthin)) yla(none) ysc(alt r(12 43)) ///
      marker(1, ms(none)) name(IL2)
      Click image for larger version

Name:	IL11.png
Views:	1
Size:	42.4 KB
ID:	1467600

      Click image for larger version

Name:	IL2.png
Views:	1
Size:	40.7 KB
ID:	1467601



      I usually sort by the magnitudes shown. If your EDUCATION is an ordered scale, you would predictably want to use its order.

      Such displays have to my mind a table flavour, so that I often move the axis title from the bottom to the top.

      If you are showing magnitudes, the axis labels and even the marker symbols seem dispensable.

      I would probably move the y axis title a little upwards and stretch the range of the second graph to 44 in a further revision.

      Comment


      • #4
        Why this is happening

        splitvallabels opcionq17
        twoway (dot q17_ opcionq17 if Secretaria=="Secretaria de Antioquia", xlabel(`r(relabel)', labsize(small)) yscale(alt range(0 3))) (lfit q17_ opcionq17 if Secretaria=="Secretaria de Antioquia")


        Click image for larger version

Name:	brr.png
Views:	1
Size:	18.4 KB
ID:	1570225

        Comment


        • #5

          Nothing is reproducible from #4 because you don't, give a data example. Please refer to https://www.statalist.org/forums/help#stata and show us the results of


          Code:
          dataex q17_ opcionq17 if Secretaria=="Secretaria de Antioquia"

          Comment

          Working...
          X