Announcement

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

  • Horizontal Bar graph order and width

    Hi there,

    First of all I am trying to change the widths of the bars in this command (see picture):

    Code:
    graph hbar cbcov tuden if time == 2014 & inlist(country,"ESP","FRA","ITA","PRT","NLD" ) , over(country, sort(order1))  ///
        name("ILO_IR_southern")                        ///
        title("Collective Bargaining in Europe")     ///
        subtitle("Southern European systems")         ///
        graphregion(color(white))                     ///
        legend( label(1 Coverage) label(2 Density) region(lwidth(none))) ///
        asyvars bar(1, fcolor(black) lwidth(none) ) bar(2, fcolor(red) lwidth(none)  )
    Is there a way to do that?

    Secondly, I am trying to sort the graph according to the variable cbcov in descending order for which I created the variable order1 based on country, so countries with high 'coverage' i.e. cbcov would appear on top, however if I write the code above it wouldn't sort whereas if I run just the first line it sorts the graph but without formating the graph as I want. Is there a solution?
    Click image for larger version

Name:	Annotation 2020-02-24 171633.png
Views:	1
Size:	19.5 KB
ID:	1538178

  • #2
    I am trying to change the widths of the bars
    Changing the gap() will shrink the bars.

    Comment


    • #3
      Thanks for this Nick and you for you quick reply!!!!

      I tried that but it doesn't do quite what I want, I just want to shrink the size of the bars without leaving a space between the black and the red ones. Apart from that, any help about the second issue would be much appreciated.

      Comment


      • #4
        Now I don't understand what you want. There is no space between black and red bars to shrink.

        Sorry, but I didn't understand your second question in #1 without a data example.

        Comment


        • #5
          Regarding the first question, if I set the gap() option then both bars are thinner but set appar as in the picture attached, whereas I am just trying to make them thinner not set appart:
          Code:
          graph hbar cbcov tuden if year == 2014 & inlist(country,"ESP","FRA","ITA","PRT","NLD" ) ,  over(country, sort(order1) gap(400) )  ///
              name("ILO_IR_southern")                                                            ///
              subtitle("Southern European systems")                                             ///
              graphregion(color(white))                                                         ///
              legend( label(1 Coverage) label(2 Density) region(lwidth(none)))                 ///
              asyvars bar(1, fcolor(black) lwidth(none) ) bar(2, fcolor(red) lwidth(none)  )
          Click image for larger version

Name:	Annotation 2020-02-25 150339.png
Views:	1
Size:	33.1 KB
ID:	1538345


          For the second question I have this structure in my data:

          Code:
               | country   year   cbcov   tuden |
               |--------------------------------|
           10. |     ARG   2014      51    27.7 |
           23. |     AUS   2014    50.6    15.1 |
           39. |     AUT   2014      98    27.7 |
           56. |     BEL   2014      96    53.8 |
           63. |     BGR   2014    12.2    13.9 |
               |--------------------------------|
           73. |     BRA   2014    70.5    16.9 |
           88. |     CAN   2014    30.4    28.4 |
           99. |     CHE   2014    49.2    16.1 |
          105. |     CHL   2014    18.1      17 |
          122. |     COL   2014    12.3     9.7 |
               |--------------------------------|
          128. |     CRI   2014     9.3    12.4 |
          146. |     CYP   2014    47.7    47.7 |
          161. |     CZE   2014    45.4    12.9 |
          177. |     DEU   2014    57.8    17.7 |
          187. |     DNK   2014    83.5    69.3 |
          I am trying to graph the variables 'cbcov' and 'tuden' for the selected countries in descending order of according to 'cbcov'. Then I can either sort them without formatting the graph or formatting the graph without sorting them.

          The dummy 'order1' variable that I have created for such purpose is defined as follows:
          Code:
          gen     order1 = 1 if country == "FRA"
          replace order1 = 2 if country == "NLD"
          replace order1 = 3 if country == "ESP"
          replace order1 = 4 if country == "ITA"
          replace order1 = 5 if country == "PRT"
          I hope this clarifies

          KR

          Comment


          • #6
            First off, are cover and density measured in the same units or is it just fortuitous that their values are roughly similar? Many people would be queasy about showing bars side by side if the units vary.

            It seems that you are not really getting my hint about a data example. Please back and up read https://www.statalist.org/forums/help#stata to get a good idea of how best to show data.
            Yours is useful, but needs some surgery to be used.

            Also, there is there is no match between your graph data and your example data, but it seems that we might just as well choose any 5 countries.

            You made gap() enormous and then don't like the result. That has to imply not going so far. Otherwise, why not vary ysize() as another way to do it?

            Code:
            clear 
            input id str3 country   year   cbcov   tuden 
             10.      ARG   2014      51    27.7 
             23.      AUS   2014    50.6    15.1 
             39.      AUT   2014      98    27.7 
             56.      BEL   2014      96    53.8 
             63.      BGR   2014    12.2    13.9 
            end 
            
            label var cbcov Coverage 
            label var tuden Density 
            
            set scheme s1color 
            
            graph hbar (asis) cbcov tuden, over(country, sort(cbcov) descending) ysize(2.5)

            Comment

            Working...
            X