Announcement

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

  • Two Questions About Spineplot Axis Labels

    I have two questions about adjusting axis labels with NJC's spineplot.

    1) First, I am trying to create a spineplot (v1.0.4 1 Nov 2007) with less sparse labeling on the second x axis.

    Here's an example:

    Code:
    sysuse auto
    spineplot foreign rep78, percent ylab(0(10)100, axis(2)) name(first, replace)
    spineplot foreign rep78, percent ylab(0(10)100, axis(2)) xlab(0(10)100, axis(1)) name(second, replace)
    I would have thought the second command would accomplish this, but it merely seems to change the scale from percent to frequency. Is there a way around this?

    2) My second question concerns modifying one of the categorical value labels on the first x axis. Here's an example:

    Code:
    sysuse auto, clear
    label define rep78 1 "One" 2 "Two" 3 "Three" 4 "Four" 5 "Five"
    lab values rep78 rep78
    spineplot foreign rep78, percent ylab(0(10)100, axis(2)) xlab(0(10)100, axis(1)) xlab(, axis(2)) xlab(3 "III", add labcolor(red) custom axis(2)) name(third, replace)
    This gets the label in the wrong place. I can hack it by doing something like this:

    Code:
    label define rep78 1 "One" 2 "Two" 3 "III" 4 "Four" 5 "Five", modify
    spineplot foreign rep78, percent ylab(0(10)100, axis(2)) xlab(0(10)100, axis(1)) xlab(, axis(2)) xlab(25 "III", add labcolor(red) custom axis(2)) name(fourth, replace)
    Unfortunately, this requires knowing where to put the label and the new label must be the same as the one it is trying to cover up. To avoid the second limitation, I tried redefining the label to be a space:

    Code:
    label define rep78 1 "One" 2 "Two" 3 "`=uchar(32)'" 4 "Four" 5 "Five", modify
    This did not work. Is there any way to do this that relaxes both constraints?


  • #2
    Thanks for your interest in spineplot (SJ), a program written, I think, because someone asked how to do these plots in Stata. I stopped a long way short of a more general mosaic plot program, partly because I've got no sense that such plots are really useful except interactively, and partly because it was a more difficult problem.

    Spineplots in my experience work quite well for about 20% of applications, are a bit of a mess in 60%, and an awful mess in 20%. I just made up those numbers, but I will stick with the experience that they're often disappointing, and although I enjoyed writing the article, I have not revisited the idea since.

    To the questions: This is a 2007 program: clearly it should still work, but that means I can't recall vividly exactly why I programmed it as I did.

    1)

    You're being bitten here by the fact that the x axis scale is really a cumulative frequency scale. Here is a work-around for you using mylabels (SSC)

    Code:
    sysuse auto 
    count if !missing(foreign, rep78)
    mylabels 0(10)100, myscale(`r(N)'*(@/100)) local(xla)
    spineplot foreign rep78, percent ylab(0(10)100, axis(2)) xlab(`xla', axis(1)) name(third)
    2)

    This is a more complicated version of the same problem. spineplot should probably work with a cumulative proportion or percent scale but that wouldn't help much here as you want to change the 3rd label on the axis. As the program places the 3rd label in the middle of the 3rd bar, that is based on a bin midpoint on a cumulative scale, which is hard to hack except after your own private calculation.

    Certainly there is no way that xlabel() has the sense of 3 as meaning the 3rd label.

    The easiest solution is just to fix the value labels before you use them, not try to do that on the fly. The next easiest solution is to use the Graph Editor.


    Comment


    • #3
      This all makes a lot of sense. Thanks for your help again!

      Comment


      • #4
        Although 2) is more difficult to fix without introducing elaborate extra syntax, 1) represents a perfectly reasonable preference. I will update the code and help to make it easier.

        Comment


        • #5
          Thanks again to Dimitriy V. Masterov for flagging this.

          Thanks to Kit Baum, an updated version is now on SSC and will also appear with Stata Journal 16(2).

          Comment


          • #6
            Thanks for adding this, @NickCox!

            Comment

            Working...
            X