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

  • Long legend text from labels

    Humbly trying out this forum for the first time, hoping to learn from you smart, helpfull people

    My problem is that half the text from my labels disappear:

    I use the graph bar command to generate stacked bars to show the distribution of categorized data (11 categories - variabel "akt_kat") from 21 individual people (variabel "person")

    .graph bar, over(akt_kat) over(person, label(angle(90))) asyvars percentage stack ///
    .legend(region(lstyle(none))title("Kategori", size (*1.0)) ) ///
    .ytitle("Procent") ///
    .b1title("Person") ///
    .xsize(5.5) ysize (5) scale(0.5) name(g1,replace)

    Only half the label text is shown in the legend.
    The label text contain up to 65 letters.

    I tried setting textwidth to (*8) and (70), but there was no change in the visual output

    I tried finding the answer myself, but officially give up now.
    Thank you in advance,

  • #2
    The most direct way would be to use the relabel() suboption with the over() option. See also:

    sysuse nlsw88, clear
    label define racelbl 1 "This is a very very very long value label" 2 "black" 3 "other", replace
    graph bar,  over(race, relabel(1 `""This is a very very" "very long value label""'))   /// 
        over(smsa) stack  asyvars percentage
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	20.5 KB
ID:	1453356


    • #3
      Thank you for your good answer, Scott.

      I came upon this option, but hoped there would be a more elegant way for stata to use the full label text since I found it illogical that I should type it manually twice.
      Since your answer confirms to me that there probably isn't, I'll use your solution, thank you.

      I hope I am within forum etiquette by asking a bit of an unrelated follow-up question; Would you happen to know, if there is a way to add legends only once to a combined graph with same legends? (Learning, learning)

      If a repost as a separate question is appropriate, I shall



      • #4
        Actually, there is a program by Nick Winter -splitvallabels- (ssc inst splitvallabels) which creates the relabel() option automatically:

        sysuse nlsw88, clear
        label define racelbl 1 "This is a very very very long value label" 2 "black" 3 "other", replace
        splitvallabels race , length(25)
        graph bar,  over(race, relabel(`r(relabel)'))   /// 
            over(smsa) stack  asyvars percentage
        Yes, unrelated questions should in a new thread. That said

        . search common legend
         grc1leg from
            grc1leg.  Combine graphs into one graph with a common legend. / Program by
            Vince Wiggins, StataCorp <>. / Statalist distribution,
            16 June 2003. / Exactly like -graph combine- but shows a single common
            legend for all / combined graphs. / Distribution-Date: 02jun2010
        grc1leg2 from
            {cmd:grc1leg2}. Add a common legend to combined graphs. / {cmd:grc1leg2},
            like {help graph combine}, arrays separately drawn / graphs as panels in a
            single combined graph.  However, / {cmd:grc1leg2} suppresses the legends
            in the individual graphs / and adds a common legend taken from one of