Announcement

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

  • How to edit the height of a bar graph ?

    Hello dear community,
    I would like to edit the height of a stacked bar graph I construct. Here is the command
    Code:
     graph bar var1 var2, over(country,label(angle(90) labsize(*0.85))) stack ///
     graphregion(color(white)) ytitle("Percent") yla(,nogrid) percentage ///
     legend(label(1 "var1") label(2 "var2") pos(6) ring(20))
    and the output looks like this:

    Click image for larger version

Name:	Capture_stata.PNG
Views:	1
Size:	79.2 KB
ID:	1635745





    As you can see, the countries' names don't appear fully. I would like to diminish the height of the bars, and make the countries' names appear fully, and find a place for the legend below the graph. Can anyone help me, please ? Attached is the data. data.dta

  • #2
    It's hard to read the country names. Have you considered graph hbar?

    Comment


    • #3
      The percents of variables 1 and 2 add to 100, necessarily. You would get a much simpler and more intelligible graph by showing with graph dot

      1. one percent only

      2. names given horizontally

      3. countries sorted by the variable shown

      Comment


      • #4
        You need to expand the outer margin for the labels to be visible. Nick's advice amounts to the following:

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str13 country double(var1 var2)
        "Angola"         5105251708  3888692980
        "Benin"           317989231  1036438617
        "Botswana"       1221370451  2665325722
        "Burkina Faso"   1018093946  1338746457
        "Burundi"         134442423   325861304
        "Côe d'Ivoire"  2420799729  4995657054
        "Cabo Verde"      164886567   241625244
        "Comoros"          45271558    69477553
        "Congo"          2005960440   762452146
        "Egypt"         15836345615 46209280623
        "Eswatini"        320048313   752773261
        "Ethiopia"       5018858165  5678614915
        "Gambia"           33845381   120320160
        "Ghana"          3302891960  4544705971
        "Kenya"          4075670325  6930733440
        "Madagascar"      752508978  1745717106
        "Mauritius"      1029290358  1735449185
        "Morocco"       13778158554 22600690509
        "Mozambique"     1680913379  2575354636
        "Namibia"        1668205554  3416707462
        "Nigeria"       13618265548 10998657164
        "Rwanda"          680124485  1046621481
        "Senegal"        1531313472  3486329728
        "South Africa"  26078796365 36946850847
        "Sudan"          2593453023  4532854724
        "Togo"            266675762   939402683
        "Uganda"         1356746922  2810503450
        "Tanzania"       2459312505  3195116481
        "Zambia"         2845010325  4595067935
        "Zimbabwe"       1431909054  2277273282
        end
        
        graph dot var1 var2, over(country,label(angle(360)  labsize(*0.85) ) axis(outergap(*30)) ///
        sort(1))  graphregion(color(white)) ytitle("Percent") yla(,nogrid) percentage linetype(line) ///
        lines(lc(gs12) lw(vthin)) legend(off)  marker(1, msy(oh)) marker(2, msy(none)) ///
        title("Some title describing var1")
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	84.8 KB
ID:	1635759

        Comment


        • #5
          Thanks a lot Nick Cox and Andrew Musau. It works.

          Comment


          • #6
            You could go even further and play with exclude0 as an option. The point is surely to compare countries' values with each other, not with zero.

            Comment

            Working...
            X