Announcement

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

  • Unable to remove the x axis labels from my graph

    I'm trying to generate a graph with the x axis labels removed but every time I run my do file the x axis labels are still there.
    When the graph is generated I can invoke the graph editor, click on the x axis and uncheck 'show labels' to remove them but how can I do this in my stata do file?
    From the Stata manual I thought it was pretty simple:

    Code:
    xlabel(, nolabels)
    But this isn't working... The full code for the graph is below:

    Code:
    clear
    use `temp'BA_FINAL_2302
    twoway (connected change assess_date, ///
    yline(0, lpattern(shortdash) lwidth(vthin) lcolor(green)) ///
    tline(15Feb2016, lwidth(vvthin) lcolor(blue)) tmlabel(15Feb2016 "RT start" , add angle(vertical) labsize(*1.0)) ///
    tline(03Mar2016, lwidth(vvthin) lcolor(blue)) tmlabel(03Mar2016 "RT stop"  , add angle(vertical) labsize(*1.0)) ///
    tline(30Nov2015 21Dec2015 13Jan2016 27Apr2016 18May2016 8Jun2016, lpattern(shortdash) lwidth(vthin)) ///
    sort mlabel(change) mlabsize(medium)), ytitle(% change) xtitle(Assessment Date) ///
    ylabel(, labsize(medium) angle(horizontal)) xlabel(, nolabels) ///
    by(, title(Subject 2302)) by(, legend(off)) by(parameter, yrescale holes (3 4 5))
    graph save `output'test2302, replace
    Any idea what I'm doing wrong here?

  • #2
    I couldn't reproduce your problem with the auto data.

    Code:
    sysuse auto, clear
    tw lfit price mpg, xlabel(, nolabels)
    This behaves exactly as expected and removes the x-axis labels. Have you tried stripping the command down to it's most basic form? You might be able to build it back piece by piece to see where the problem is. Maybe start here

    Code:
    tw connected change assess_date, xlabel(, nolabels)
    If that works then you can start building it piece by piece until you pinpoint the problem or end up with a finished graphic.

    Lance

    Comment


    • #3
      What you're doing wrong is

      1. Being bitten by what looks like a bug or at least an unintended limitation, I think. Not your fault!

      2. Not giving us a reproducible example. We can't use your code without your data.

      In the spirit of Lance's example, which lacks a by() option which I suspect is the main issue here,


      Code:
      sysuse auto, clear
      
      scatter mpg weight, by(foreign) xla(, nolabels)
      
      scatter mpg weight, by(foreign) xla(, labcolor(bg) tlength(0))
      I note that xlabels(, nolabels) seems to be ignored but I don't understand why. Similarly it is hard to get rid of the ticks.

      A subterfuge is that if you set the label colour to background and the tick lengths to zero, then in each case they are still there but hard to see.

      Comment


      • #4
        Thanks guys, I did a bit more testing yesterday and homed in on the by() code also.

        I appreciate the workaround and have implemented this for now.

        Can/should I report this as a potential bug?

        Comment

        Working...
        X