Announcement

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

  • Space between categories in bar chart

    Dear all,
    I would like to know your advise on the following issue:

    I realized the attached graph with the following commands:

    - graph bar varia, over(quint, gap(*.1)) over(indica) asyvars ///
    title("Variazione nell'occupazione - 1992-2015 (punti percentuali)", size(medium)) ///
    ylabel(-10(5)20,labsize(small)) ///
    leg(rows(1)) ///
    scheme(s1mono)-

    I would like to separate a bit the five blocks of bars (are too close, and this makes them a bit messy to read).
    Do you have any suggestion? Thanks a lot in advance, best, G. Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.6 KB
ID:	1463663

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte quint float varia byte indica
    1  -8.343537 1
    2  -2.959802 1
    3  .12181555 1
    4  -2.734728 1
    5  13.916252 1
    1  -5.167853 2
    2 -2.2559142 2
    3  -5.187787 2
    4   3.259291 2
    5  9.3522625 2
    1  -2.425655 3
    2  -4.566458 3
    3  -9.480151 3
    4  1.9130713 3
    5  14.559194 3
    1  -.5497355 4
    2  -10.10165 4
    3 -3.4684265 4
    4  -3.275045 4
    5   17.39486 4
    1  -9.566322 5
    2  2.3162832 5
    3   2.455407 5
    4   6.096104 5
    5  -1.301472 5
    end
    label values quint quint
    label def quint 1 "Q1", modify
    label def quint 2 "Q2", modify
    label def quint 3 "Q3", modify
    label def quint 4 "Q4", modify
    label def quint 5 "Q5", modify
    label values indica indica
    label def indica 1 "Istruzione", modify
    label def indica 2 "Retribuzione", modify
    label def indica 3 "Isei", modify
    label def indica 4 "Prestigio", modify
    label def indica 5 "Soddisfazione lavorativa", modify

  • #2
    Thanks for the example data and code. Changing the gap is easy enough -- you already know the technique -- but this needs also, I suggest, one label to be put on two lines and a monotonic change in colours for your bins (quintile bins???). That will improve your readers' soddisfazione.

    I find that pale bars can be difficult to see without a stronger outline colour, so add that to all bars.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte quint float varia byte indica
    1  -8.343537 1
    2  -2.959802 1
    3  .12181555 1
    4  -2.734728 1
    5  13.916252 1
    1  -5.167853 2
    2 -2.2559142 2
    3  -5.187787 2
    4   3.259291 2
    5  9.3522625 2
    1  -2.425655 3
    2  -4.566458 3
    3  -9.480151 3
    4  1.9130713 3
    5  14.559194 3
    1  -.5497355 4
    2  -10.10165 4
    3 -3.4684265 4
    4  -3.275045 4
    5   17.39486 4
    1  -9.566322 5
    2  2.3162832 5
    3   2.455407 5
    4   6.096104 5
    5  -1.301472 5
    end
    label values quint quint
    label def quint 1 "Q1", modify
    label def quint 2 "Q2", modify
    label def quint 3 "Q3", modify
    label def quint 4 "Q4", modify
    label def quint 5 "Q5", modify
    label values indica indica
    label def indica 1 "Istruzione", modify
    label def indica 2 "Retribuzione", modify
    label def indica 3 "Isei", modify
    label def indica 4 "Prestigio", modify
    label def indica 5 `" "Soddisfazione" "lavorativa" "', modify
    
    graph bar (asis) varia, over(quint, gap(*.1)) over(indica, gap(*2)) asyvars ///
    title("Variazione nell'occupazione - 1992-2015 (punti percentuali)", size(medium)) ///
    ylabel(-10(5)20,labsize(small)) leg(rows(1)) scheme(s1mono) ///
    bar(1, bfc(gs3) blc(black)) bar(2, bfc(gs6) blc(black)) ///
    bar(3, bfc(gs9) blc(black))  bar(4, bfc(gs12) blc(black)) bar(5, bc(gs15) blc(black))
    Click image for larger version

Name:	quintile_bar.png
Views:	1
Size:	25.8 KB
ID:	1463665

    Comment


    • #3
      Dear Nick,
      thanks a lot for your suggestions, you definitely improved my 'soddisfazione'

      Have a nice day, best, G.

      Comment


      • #4
        Consider also

        Code:
        yla(, ang(h))

        Comment


        • #5
          Dear Nick,
          what this command does? I tried but I did not see any different (maybe I put it in a wrong position).

          Can I profit of your kindness for a further question?
          I need to combine three graphs in a row, and showing only in the first one the labes. But the command -axis outergap- seems to not working; also I would like to reduce the size of these labels (both operations to make more room for the three graphs, attached as before; I think I should resize them using fxsize, right?)

          Could you suggest me something please?

          Thanks a lot, best, G.

          Code:
          la def uomo ///
                          0 "Donne" ///
                          1 "Uomini", modify            
          la val  uomo uomo 
          la var uomo "uomo"
          
          *
          la def setto ///
                          1 "Legislatori, ufficiali e managers" ///
                          2 "Professionisti" ///
                          3 "Tecnici e professionisti associati" ///
                          4 "Impiegati" ///
                          5 "Addetti ai servizi e alle vendite" ///
                          6 "Qualificati nella pesca e agricoltura" ///
                          7 "Artigiani e operai" ///
                          8 "Operatori di macchina e di impianti e assemblatori" ///
                          9 "Occupazioni dequalificate", modify              
          la val  setto setto 
          la var setto "settore"
          
          set dp comma
          graph hbar perc, over(uomo) over(setto, axis(outergap(*2) gap(*.1) relabel(6 `""Qualificati nella pesca""e agricoltura""' ///
                                                                          5 `""Addetti ai servizi""e alle vendite""' ///
                                                                          3 `""Tecnici e""professionisti associati""' ///
                                                                          8 `""Operatori di macchina e di""impianti e assemblatori""')) ///
          asyvars stack ///
          title("Distribuzione di genere nelle professioni - 1992", size(small)) ///
          ylabel(0(5)20,labsize(small)) ///
          leg(rows(1)) ///
          fxsize(80) ///
          blabel(bar,position(outside)) ///
          scheme(s1mono)
          graph save isco92.gph, replace
          
          graph hbar perc, over(uomo) over(setto, gap(*.1) relabel(1 "" 2 "" 3 "" 4 "" 5 "" 6 "" 7 "" 8 "" 9 "")) ///
          asyvars stack ///
          title("Distribuzione di genere nelle professioni - 2008", size(small)) ///
          ylabel(0(5)20,labsize(small)) ///
          leg(rows(1)) ///
          blabel(bar,position(outside)) ///
          scheme(s1mono)
          graph save isco08.gph, replace
          
          graph hbar perc, over(uomo) over(setto, gap(*.1) relabel(1 "" 2 "" 3 "" 4 "" 5 "" 6 "" 7 "" 8 "" 9 "")) ///
          asyvars stack ///
          title("Distribuzione di genere nelle professioni - 2015", size(small)) ///
          ylabel(0(5)20,labsize(small)) ///
          leg(rows(1)) ///
          blabel(bar,position(outside)) ///
          scheme(s1mono)
          graph save isco15.gph, replace
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	62.8 KB
ID:	1463689


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(uomo setto) float perc
          0 1 5.1
          0 2 6.9
          0 3 7.1
          0 4 8.7
          0 5 6.5
          0 6  .7
          0 7 1.4
          0 8 1.5
          0 9 4.3
          1 1 6.2
          1 2 5.7
          1 3 9.7
          1 4 4.6
          1 5   4
          1 6 2.1
          1 7  13
          1 8 6.9
          1 9 5.8
          end

          Comment


          • #6
            yla(, ang(h)) is not a command, but an option.

            I will try to get to your larger question later today.
            Last edited by Nick Cox; 27 Sep 2018, 05:28.

            Comment


            • #7
              Dear Nick,
              yes, sorry for my not correct language, of course I put it as an option (in brackets).

              It would be unvaluable your feedback, today I should deliver this stuff and I am struggling with it without rest since this night.

              Thanks a lot, G.

              Comment


              • #8
                There is not enough data in the example to replicate your graph. I think the basic strategy would be better as something like

                Code:
                graph hbar perc, over(uomo) over(setto, gap(*.1) asyvars stack by(anno, row(1)
                where anno records which year you have.

                Comment


                • #9
                  Dear Nick,
                  teh strategy I followed was woring on 3 separate dataset and then combining the 3 graphs with:

                  grc1leg isco92.gph isco08.gph isco15.gph, span ycommon col(3) scheme(s1mono)

                  Do you think it woud be better working on an unique dataset?
                  In any case, may you be so kind to explain me how to fix the gap of labels (with respect to the left bound of the graph) and their size (in the first of the three graph)?

                  This would be fine to me.

                  Thanks in advance, G

                  Comment


                  • #10
                    My advice was -- and is -- not to do that. Don't combine graphs: lean on by().

                    Also, do make sure that you explain community-contributed commands you refer to (here grc1leg).

                    I still don't have a data example with all three years, so I just cloned the data you gave in #5.

                    My attempts to do implement #8 didn't work out well. But here is another experiment using tabplot(Stata Journal). My sense is that you have scope for slightly longer labels, but not much longer.

                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input byte(uomo setto) float perc
                    0 1 5.1
                    0 2 6.9
                    0 3 7.1
                    0 4 8.7
                    0 5 6.5
                    0 6  .7
                    0 7 1.4
                    0 8 1.5
                    0 9 4.3
                    1 1 6.2
                    1 2 5.7
                    1 3 9.7
                    1 4 4.6
                    1 5   4
                    1 6 2.1
                    1 7  13
                    1 8 6.9
                    1 9 5.8
                    end
                    
                    expand 3
                    bysort uomo setto : gen anno = real(word("1992 2008 2015", _n))  
                    
                    la def uomo 0 "Donne" 1 "Uomini", modify            
                    la val uomo uomo
                    la var uomo "uomo"
                    
                    la def setto ///
                                    1 "Legislatori" ///
                                    2 "Professionisti" ///
                                    3 "Tecnici" ///
                                    4 "Impiegati" ///
                                    5 "Addetti" ///
                                    6 "Pesca e agricoltura" ///
                                    7 "Artigiani" ///
                                    8 "Macchina" ///
                                    9 "Dequalificate", modify              
                    la val setto setto
                    la var setto "settore"
                    
                    set dp comma
                    tabplot setto anno [iw=perc], by(uomo, note("") row(1) ///
                    title("Distribuzione di genere nelle professioni")) ///
                     scheme(s1mono) showval(format(%2.1f) mlabsize(small)) xtitle("") ytitle("")
                    Click image for larger version

Name:	piccito.png
Views:	1
Size:	24.9 KB
ID:	1463727





                    Last edited by Nick Cox; 27 Sep 2018, 09:57.

                    Comment


                    • #11
                      Dear Daniel,
                      thanks a lot, I've already tried with the command - tabplot -, but I don't like much the graphical effect.

                      Why do you discourage to combine graphs? Is it not efficient?

                      In any case, thanks a lot for your kindness.

                      Best, G.

                      Comment


                      • #12
                        I don't know who Daniel is here.

                        Your approach just produced a mess with much repetition. That's, I think, why you asked the question and why I discourage it. The main point is that separate graphs can't know about each other. Also, getting the sizes right is hard work.

                        I don't really understand your data and whether males and females can be stacked here (are parts of the same total) or whether the percents are for different bases.
                        Last edited by Nick Cox; 28 Sep 2018, 01:20.

                        Comment


                        • #13
                          Dear Nick,
                          sorry for the error in the name.

                          I got what you mean about the graphs, thanks for your advise.

                          My data are the percentage of male and female which are part of each professional group. Whit that visualization I would like to show for each profession its change (in proportion of employed based on the total workforce) and the proportion of male and female which are in each profession (again, based on the total workforce).

                          Do you think it is not a good way of render this idea?

                          Comment


                          • #14
                            Sorry, but I still understand what totals the percents refer to. Clearly male percent + female percent != 100.

                            In graphing a three-way table, you have to decide which comparisons you most want to make.

                            Comment


                            • #15
                              Dear Nick,
                              yes, male percent + female percent != 100 in each profession, but:
                              male percent + female percent == 100 for the total workforce (that is my goal).

                              Going back to #5, do you have clue on why axis(outergap(*2) does not work? This would help me to make the graphs clearer.

                              Thanks, G,

                              Comment

                              Working...
                              X