Announcement

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

  • Hiding bar of one category in -tabplot-

    Dear users,
    I am using -tabplot- to realize the following graph (see attachment) and I would like to add one category more (in the last row, below 'Occupazioni dequalificate') which lists the total % of occupation for each year for 'Donne' and 'Uomini'. Since this will be obviously a much higher number (some xx,x%) I would like to show only the value but not the bar.

    I tried the option -if- in the commands but it does not work.
    Do you have any clue? Thanks a lot, best, G.

    Here the data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(uomo setto) float perc byte anno
    0 1  .5 1
    0 2   4 1
    0 3 4.4 1
    0 4 6.7 1
    0 5 7.3 1
    0 6 1.9 1
    0 7 3.3 1
    0 8 1.5 1
    0 9 4.2 1
    1 1 2.4 1
    end
    Here the script
    Code:
    label values uomo uomo
    label def uomo 0 "Donne", modify
    label def uomo 1 "Uomini", modify
    label values setto setto
    label def setto 1 "Legislatori, ufficiali e managers", modify
    label def setto 2 "Professionisti", modify
    label def setto 3 "Tecnici e professionisti associati", modify
    label def setto 4 "Impiegati", modify
    label def setto 5 "Addetti ai servizi e alle vendite", modify
    label def setto 6 `" "Qualificati nella pesca" "e agricoltura" "', modify
    label def setto 7 "Artigiani e operai", modify
    label def setto 8 `" "Operatori di macchina e" "di impianti e assemblatori" "', modify
    label def setto 9 "Occupazioni dequalificate", modify
    
    label define anno 1 "1992" 2 "2008" 3 "2015" 4"what"
    label values anno anno
    
    gen percshow = string(perc, "%04,1fc")
    tabplot setto anno [iw=perc], by(uomo, compact note("") title("Distribuzione di genere nelle professioni", place(e))) ///
    subtitle(, fcolor(none)) showval(percshow, mlabsize(vsmall)) ///
    xtitle("") ytitle("") yla(, labsize(medsmall)) ///
    separate(uomo) bar1(bfcolor(red*0.2) blcolor(red)) bar2(bfcolor(blue*0.2) blcolor(blue)) ///
    scheme(s1mono)
    Click image for larger version

Name:	a.png
Views:	1
Size:	168.5 KB
ID:	1475371

  • #2
    tabplot is from the Stata Journal, as you are asked to explain.

    if is a qualifier here, not an option.

    Your data example and graph don't match.

    You could do it. Just add further observations to the data with a new category and new values. There's nothing in tabplot that does that for you on the fly. You must edit the data.

    Then you would need to edit the graph in the Graph Editor.

    Alternatively, you could write your own program.

    EDIT Above all else, don't put the real totals as data. If you do, the other bars will shrink. In fact you might get away with entering minute values such as 1e-6 for all the totals, so that the bars are not visible. Then edit in the real numbers as text.
    Last edited by Nick Cox; 18 Dec 2018, 06:53.

    Comment


    • #3
      Dear Nick,
      thanks for your response.

      You are right that I have manually edit the data, and add a further category with observation equal to the new value that I need (the total of the workforce for 'Donne' and 'Uomini' in the three years).
      The problem is that once I do that, I obtain the same graph but with the last bar very high, while I would like to now show the last high bar (only the values associated to it).

      Here the code, attached the graph that I obtain (I would like the same, but without last bat). With -graph edit- I can not specify to hide only one bar.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte(uomo setto) float perc byte anno
      0  1   .5 1
      0  2    4 1
      0  3  4.4 1
      0  4  6.7 1
      0  5  7.3 1
      0  6  1.9 1
      0  7  3.3 1
      0  8  1.5 1
      0  9  4.2 1
      0 10 30.4 1
      1  1  2.4 1
      1  2  3.5 1
      1  3  8.8 1
      1  4  6.6 1
      1  5  8.7 1
      1  6  3.7 1
      1  7 18.4 1
      1  8  7.5 1
      1  9  6.5 1
      1 10   44 1
      0  1    3 2
      0  2  3.7 2
      0  3 10.5 2
      0  4    7 2
      0  5  6.4 2
      0  6   .6 2
      0  7  2.3 2
      0  8  1.7 2
      0  9    4 2
      0 10 31.2 2
      1  1  5.7 2
      1  2  5.1 2
      1  3 10.9 2
      1  4  4.6 2
      1  5  4.7 2
      1  6    2 2
      1  7 14.9 2
      1  8  7.4 2
      1  9  5.2 2
      1 10 33.2 2
      0  1  5.1 3
      0  2  6.9 3
      0  3  7.1 3
      0  4  8.7 3
      0  5  6.5 3
      0  6   .7 3
      0  7  1.4 3
      0  8  1.4 3
      0  9  4.3 3
      0 10 31.7 3
      1  1  6.1 3
      1  2  5.7 3
      1  3  9.7 3
      1  4  4.6 3
      1  5    4 3
      1  6  2.1 3
      1  7   13 3
      1  8  6.9 3
      1  9  5.8 3
      1 10 36.2 3
      end
      Click image for larger version

Name:	t.png
Views:	1
Size:	50.5 KB
ID:	1475410

      Comment


      • #4
        I already addressed this problem in '#2 EDIT. You are going to have to lie to get a graph you like, and then to fix the lie in the Graph Editor.

        Comment


        • #5
          Dear Nick,
          Ok, I got what you mean, thanks a lot.

          Only a small further question: If I would like to expand the comparison at more than two categories (lets' say, "Donne", "Uomini", "North", "South"), I can edit the data as follo I guess:


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(uomo setto) float perc byte anno str4 percshow
          0  1       .5 1 "0,5"
          0  2        4 1 "4,0"
          0  3      4.4 1 "4,4"
          0  4      6.7 1 "6,7"
          0  5      7.3 1 "7,3"
          0  6      1.9 1 "1,9"
          0  7      3.3 1 "3,3"
          0  8      1.5 1 "1,5"
          0  9      4.2 1 "4,2"
          0 10        0 1 "0,0"
          1  1      2.4 1 "2,4"
          1  2      3.5 1 "3,5"
          1  3      8.8 1 "8,8"
          1  4      6.6 1 "6,6"
          1  5      8.7 1 "8,7"
          1  6      3.7 1 "3,7"
          1  7     18.4 1 "18,4"
          1  8      7.5 1 "7,5"
          1  9      6.5 1 "6,5"
          1 10        0 1 "0,0"
          0  1        3 2 "3,0"
          0  2      3.7 2 "3,7"
          0  3     10.5 2 "10,5"
          0  4        7 2 "7,0"
          0  5      6.4 2 "6,4"
          0  6       .6 2 "0,6"
          0  7      2.3 2 "2,3"
          0  8      1.7 2 "1,7"
          0  9        4 2 "4,0"
          0 10        0 2 "0,0"
          1  1      5.7 2 "5,7"
          1  2      5.1 2 "5,1"
          1  3     10.9 2 "10,9"
          1  4      4.6 2 "4,6"
          1  5      4.7 2 "4,7"
          1  6        2 2 "2,0"
          1  7     14.9 2 "14,9"
          1  8      7.4 2 "7,4"
          1  9      5.2 2 "5,2"
          1 10        0 2 "0,0"
          0  1      5.1 3 "5,1"
          0  2      6.9 3 "6,9"
          0  3      7.1 3 "7,1"
          0  4      8.7 3 "8,7"
          0  5      6.5 3 "6,5"
          0  6       .7 3 "0,7"
          0  7      1.4 3 "1,4"
          0  8      1.4 3 "1,4"
          0  9      4.3 3 "4,3"
          0 10        0 3 "0,0"
          1  1      6.1 3 "6,1"
          1  2      5.7 3 "5,7"
          1  3      9.7 3 "9,7"
          1  4      4.6 3 "4,6"
          1  5        4 3 "4,0"
          1  6      2.1 3 "2,1"
          1  7       13 3 "13,0"
          1  8      6.9 3 "6,9"
          1  9      5.8 3 "5,8"
          1 10 1.00e-06 3 "0,0"
          2  1        2 1 "2,0"
          2  2      4.5 1 "4,5"
          2  3      9.3 1 "9,3"
          2  4      9.9 1 "9,9"
          2  5     10.8 1 "10,8"
          2  6        3 1 "3,0"
          2  7     14.7 1 "14,7"
          2  8      6.7 1 "6,7"
          2  9      5.6 1 "5,6"
          2 10 1.00e-06 1 "0,0"
          3  1       .9 1 "0,9"
          3  2        3 1 "3,0"
          3  3      3.9 1 "3,9"
          3  4      3.4 1 "3,4"
          3  5      5.2 1 "5,2"
          3  6      2.6 1 "2,6"
          3  7        7 1 "7,0"
          3  8      2.3 1 "2,3"
          3  9      5.1 1 "5,1"
          3 10 1.00e-06 1 "0,0"
          2  1      5.7 2 "5,7"
          2  2      5.8 2 "5,8"
          2  3     15.4 2 "15,4"
          2  4      8.4 2 "8,4"
          2  5      7.5 2 "7,5"
          2  6      1.7 2 "1,7"
          2  7     11.9 2 "11,9"
          2  8      6.6 2 "6,6"
          2  9      5.1 2 "5,1"
          2 10 1.00e-06 2 "0,0"
          3  1        3 2 "3,0"
          3  2        3 2 "3,0"
          3  3        6 2 "6,0"
          3  4      3.2 2 "3,2"
          3  5      3.7 2 "3,7"
          3  6        1 2 "1,0"
          3  7      5.3 2 "5,3"
          3  8      2.5 2 "2,5"
          3  9      4.2 2 "4,2"
          3 10 1.00e-06 2 "0,0"
          end
          label values uomo uomo
          label def uomo 0 "Donne", modify
          label def uomo 1 "Uomini", modify
          label values setto setto
          label def setto 1 "Legislatori, ufficiali e managers", modify
          label def setto 2 "Professionisti", modify
          label def setto 3 "Tecnici e professionisti associati", modify
          label def setto 4 "Impiegati", modify
          label def setto 5 "Addetti ai servizi e alle vendite", modify
          label def setto 6 `" "Qualificati nella pesca" "e agricoltura""', modify
          label def setto 7 "Artigiani e operai", modify
          label def setto 8 `" "Operatori di macchina e" "di impianti e assemblatori""', modify
          label def setto 9 "Occupazioni dequalificate", modify
          label def setto 10 "Totale", modify
          label values anno anno
          label def anno 1 "1992", modify
          label def anno 2 "2008", modify
          label def anno 3 "2015", modify
          The, with the following code, I do not succeed in obtaining the graph I attached before as example with the new four categories ("Donne", "Uomini", "North", "South") and only one legend in a row, but I obtain what is attached. Do you have any clue on how telling Stata to put the graph for each category in a single row and with a single legend?

          Thanks again,g Click image for larger version

Name:	tot.png
Views:	1
Size:	52.2 KB
ID:	1475418

          Comment


          • #6
            Look at your data. You have four values 0 1 2 3 for uomo. What does that mean?

            Comment


            • #7
              Dear Nick,
              yes, what I am trying to figure out is how to realize the attached graph not for two categories but for four (let's say "0 Donna-south" "1 Donna-north" "2 Men-south" "3 Men-north"), obtaining a graph in four columns (one each for 0,1,2,3) and in a row, with a unique legend.

              Something similar to what I attached in #5, but in a unique row.

              Sorry if I was not clear before.

              Thanks, G

              Comment


              • #8
                The by() option has suboptions, say row(1) to enforce a single row.That is standard documented functionality.

                You've stopped showing the tabplot code you used. But what you seem to want is 10 x 4 x 3 = 120 labelled bars when your category names are long and so take up much of the space if they are to be readable. It won't work well even if you have a lot of space to show your graph.

                Comment


                • #9
                  Dear Nick, thanks a lot for your tip, I always do not figure out where to put the proper suboptions.

                  Having done what you said lead me to the attached graph, that in line of principle is very nice. What I do not like is that, as you said in #8, the graph is too narrow and not nicely visible.
                  But there is no way to adapt the size of the graph to the whole available space? It seems that the graph is placed only in the right side of the window, and a lot of white space (useless) remains on the left. Is there any way to re-size the graph so that it optimize the blank space available?

                  Thanks in advance, best, G

                  Comment


                  • #10
                    Click image for larger version

Name:	tot.png
Views:	1
Size:	63.3 KB
ID:	1475534

                    here the graph

                    Comment


                    • #11
                      It doesn't work well, does it? The dates are all mushed up and you still need to give text instead of "2" and "3".

                      Comment


                      • #12
                        Dear Nick,
                        yes, those are provisional tests to control the size. The graph looks nice to me (except for what you just underlined), but it is a bit small.
                        Is there any chance to re-size it in order to fill properly all the available space (without leaving the left side all blank, basically)?

                        Thanks a lot, G

                        Comment


                        • #13
                          You could work harder to put more category labels on two lines.

                          Comment


                          • #14
                            Yes, you are right, that is absolutely doable, but is would solve only partially the problem, do you agree?

                            I mean, the more general question here is: when I use the suboption ,by to combine basically the same graph over different categories (4 in my last case) the resulting graph is always not efficaciously placed within the window, because (at least in my opinion) it occupies only part of the blank available space. Having the chance to re-size the graph telling Stata that it has to occupy all the white available space would improve the readability (for instance, in my case each column that represents one 'category' of -by- would have more room, make easier the fruition of the graph).

                            Is there any option in this sense?

                            Thanks as always

                            Comment


                            • #15
                              The problem is trying to show too much, not that Stata won't give you the space. What are you going to do this plot?

                              Comment

                              Working...
                              X