Announcement

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

  • Labels too long and grid in a graph

    Dear Stata Users,

    I would like to ask you some minor points on a graph.

    I created the attached graph with the following code:

    Code:
    lab var sett "sett"
    lab def sett 1"agricoltura, caccia e pesca" ///
                             2"industria, estrazione, manifatture" ///
                             3"costruzioni" ///
                             4"commercio, alberghi, ristoranti" ///
                             5"trasporti, comunicazioni" ///
                             6"intermediazioni e altre attività" ///
                             7"P.A. e difesa" /// 
                             8"istruzione, sanità, servizi sociali" ///
                             9"altri servizi", modify 
    lab val sett sett
    graph hbar v1 v3, over(sett) stack ///
    legend(order(1 "Donne" 2 "Uomini")) ///
    ytitle("") /// 
    note("", span) ///
    scheme(s1mono) ///
    per
    This is almost what I need, except for two things:

    A) I do not succeed in showing the whole name of labels, even if I make them smaller in two cases the last part of the last work does not appear (the 2 should be "industria, estrazione, manifattura" and the 8 "istruzione, sanità, servizi sociali).

    B) I do not succed in leaving the grid in the background

    Do you have any clue?

    Thanks a lot, G. Graph22.tif

  • #2
    Try smaller label size:


    Code:
     
     graph hbar v1 v3, over(sett, lab(labsize(vsmall)) stack /// legend(order(1 "Donne" 2 "Uomini")) /// ytitle("") ///  note("", span) /// scheme(s1mono) ylab( , nogrid) /// per
    Roman

    Comment


    • #3
      Dear Roman, I already tried this option, but the result (attached) as you can see is the same. Do you know if there is some limit of lenght in words that Stata can admit as labels? Graph.tif

      Comment


      • #4
        And also, do you know the option to rule out the grid?

        Thanks, G

        Comment


        • #5
          Originally posted by Giorgio Piccitto View Post
          I already tried this option
          I can't see that in your commands

          Originally posted by Giorgio Piccitto View Post
          And also, do you know the option to rule out the grid?
          It is also in my commands above after ylab options. Copy and paste my commands and see if that is what you wanted:

          Same commands repeated below as the above commands just showing the whole thing in oneline:


          Code:
          graph hbar v1 v3, over(sett,  lab(labsize(vsmall))) stack ///
          legend(order(1 "Donne" 2 "Uomini")) ///
          ytitle("") ///
          note("", span) ///
          scheme(s1mono) ylab( , nogrid)  ///
          per


          Roman

          Comment


          • #6
            Dear Roman,

            that is the code:
            Code:
            lab var sett "sett"
            lab def sett 1"agricoltura, caccia e pesca" ///
                                     2"industria, estrazione, manifatture" ///
                                     3"costruzioni" ///
                                     4"commercio, alberghi, ristoranti" ///
                                     5"trasporti, comunicazioni" ///
                                     6"intermediazioni e altre attività" ///
                                     7"P.A. e difesa" /// 
                                     8"istruzione, sanità, servizi sociali" ///
                                     9"altri servizi", modify 
            lab val sett sett
            graph hbar v1 v3, over(sett,  lab(labsize(vsmall))) stack ///
            legend(order(1 "Donne" 2 "Uomini")) ///
            ytitle("") ///
            note("", span) ///
            scheme(s1mono) ylab( , nogrid)  ///
            per
            and the attached graph is the result. The grid disappeared, but still the two labels pointed out before in my message are not complete (the 2 should be "industria, estrazione, manifattura" and the 8 "istruzione, sanità, servizi sociali).

            Thanks a lot for your tip, but do you know why Stata does not show those labels entirely?

            Thanks, G.

            Comment


            • #7
              Here the graph: Graph.tif

              Comment


              • #8
                Giorgio: Please do read the FAQ Advice. Graph images should be posted as png. Data examples to make your problem visible and reproducible are requested. Not asking questions that are easy to answer is likely to be why this thread is moving slowly, despite Roman's excellent attempts to help.

                Comment


                • #9
                  Giorgio, As Nick suggested you would get responses from wider community if you had attached the graph in "jpg/png" format. Not everyone will be encouraged to download a file from internet and open it for security reasons (Please read "how to manage attachment" section). On point, I think your labels are too large to be displayed in full if 'vsmall' option does not solve it. You can further go making it even smaller by specifying 'tiny' option but that may have legibility issue. Better, try relabeling with fewer characters, or attach the photo to exhibit for others to see and wait if anyone else have better ideas. That's all I can suggest unfortunately.
                  Roman

                  Comment


                  • #10
                    Dear NIck and Roman,
                    thanks for your answers. I remembered that the correct format was .tif, sorry for this misunderstanding.

                    In any case, the problem of labels does not consist in the fact that they are set too big, because also specifying tiny does not solve the problem that the last part of the two labels that I pointed out does not appear. At this point, my question is if Stata automatically rule out some characters if the label exceeds some prefixed lenght.

                    Sorry again for my previous mistake.

                    Best, G.

                    Comment


                    • #11
                      You are more likely to get help if you provide example data. There is a workaround to this length restriction but it may not be very efficient if you have too many long labels, i.e., use the relabel option. Here is the problem illustrated and solved


                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input float(Spesa V1 Settore)
                       10 1 1
                      150 1 2
                      200 1 3
                       75 1 4
                      125 1 5
                       50 1 6
                      160 1 7
                      140 1 8
                       40 1 9
                      120 2 1
                       70 2 2
                      190 2 3
                       75 2 4
                      125 2 5
                       20 2 6
                      200 2 7
                      140 2 8
                       50 2 9
                      end
                      label values Settore sett
                      label def sett 1 "agricoltura, caccia e pesca", modify
                      label def sett 2 "industria, estrazione, manifatture", modify
                      label def sett 3 "costruzioni", modify
                      label def sett 4 "commercio, alberghi, ristoranti", modify
                      label def sett 5 "trasporti, comunicazioni", modify
                      label def sett 6 "intermediazioni e altre attività", modify
                      label def sett 7 "P.A. e difesa", modify
                      label def sett 8 "istruzione, sanità, servizi sociali", modify
                      label def sett 9 "altri servizi", modify

                      Click image for larger version

Name:	lab1.png
Views:	1
Size:	23.2 KB
ID:	1417967


                      Here is the graph with some labels truncated

                      Code:
                      graph hbar Spesa V1, over(Settore) stack legend(order(1 "Donne" 2 "Uomini")) ///
                      ytitle("") note("", span) scheme(s1mono) per


                      Relabel truncated (2nd and 6th) labels

                      Code:
                      graph hbar Spesa V1, over(Settore, relabel(2 "industria, estrazione, ///
                      manifatture" 6 "istruzione, sanità, servizi sociali")) stack legend(order(1 "Donne" ///
                      2 "Uomini")) ytitle("") note("", span) scheme(s1mono) per

                      Click image for larger version

Name:	lab2.png
Views:	1
Size:	22.5 KB
ID:	1417968

                      Comment


                      • #12
                        Dear Andrew,
                        thanks a lot, the command relabel worked perfectly.

                        Thanks again, best, G.

                        Comment

                        Working...
                        X