Announcement

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

  • Avoid truncation of axis labels in bar graph

    Hi Statalist,

    I am trying to make a bar chart in Stata with some very long labels on the y-axis. However, some of my labels are truncated when displayed in the graph (se example). I am sure there is a way of keeping the entire label in the graph, and I am hoping that maybe one of you can tell me how to do it.
    Thanks in advance.

    I use the following code:

    graph hbar AAbw, ///
    over (MeanP501) bar(1, color(black)) bar(2, color(gs8)) ///
    over(study, label(labsize(tiny))) ///
    over(country, label(labsize(vsmall)) gap(400)) nofill ///
    ytitle("Acrylamide (μg/kg bw/day)", size(vsmall)) ///
    title("Median/mean estimated acrylamide intake" ///
    "based on DQ or both DQ and DR" ///
    " ", span size(small) color(black)) ///
    ysize(10) ///
    xsize(7) ///
    ylabel(0(0.1)0.9, labsize(vsmall)) ///
    legend(size(vsmall)) ///
    graphregion(color(white))

    Click image for larger version

Name:	Skærmbillede 2021-04-23 150530.png
Views:	1
Size:	89.0 KB
ID:	1605333

  • #2
    There are length constraints. Either shorten very long labels or use the -relabel()- option, if you want the full label to appear.

    Code:
    sysuse auto, clear
    label def rep78 1 "good" 3 "neither good nor bad, just average"
    label values rep78 rep78
    gr hbar mpg, over(rep78) scheme(s1mono)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	30.3 KB
ID:	1605343


    Code:
    gr hbar mpg, over(rep78, relabel(3 "neither good nor bad, just average")) scheme(s1mono)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	30.4 KB
ID:	1605344

    Comment


    • #3
      Thank you for your quick reply. Do you know if there is any way to do this for all labels without having to type each label manually?
      I have several graphs that each has many long labels, so I am hoping to avoid having to type each of them - especially since the order might change if I add new data to the graph.

      Comment


      • #4
        There was a suggestion to modify the ado file of graph, but making changes to the codes of official Stata commands is something that I do not do or recommend.
        https://www.statalist.org/forums/for...els-on-a-graph

        Comment


        • #5
          Thank you. It looks like I have a lot of manual work to do then

          Comment

          Working...
          X