Announcement

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

  • Manipulating Y axis using "stripplot" - getting rid of extra space/controlling margins

    Hi all,

    I've been Googling an answer to this for FAR too long and am wondering if anyone can help.

    I'm trying to graph a series of box plots using "stripplot" on STATA/IC 13.1 . I am plotting the interquartile range of birth weight (in grams) by year with 3 other line graphs overlaid:
    • smoothed lowess line for the full sample over time
    • smoothed lowess line for those in the 10th birth weight centile over time
    • smoothed lowess line for those in the 90th birth weight centile over time
    This is my code:

    Code:
     
    stripplot birthweight, over(year) vertical ///
    box(bfcolor(gs14) barw(0.2)) iqr(1.5) ms(none) ///
    addplot(lowess birthweight year, lcolor(black)  yscale(range(1500 4500)) ylabel(1500(500)4500) || ///
    lowess tenth1 year,  yscale(range(1500 4500)) ylabel(1500(500)4500) || ///
    lowess ninety1 year,  yscale(range(1500 4500)) ylabel(1500(500)4500))
    I've specified the yscale and ylabel above because I want to "zoom into" these values and not extend the Y axis to the full range of underlying birth weight data (which go from a min of ~450g to max of ~4700g).

    After manually editing the size of the X/Y axis labels for clarity, my graph looks like this:
    Click image for larger version

Name:	example1.png
Views:	1
Size:	60.6 KB
ID:	1366838

    ::Please ignore the fact that the colours are terrible!:: All I want to do is get rid of that huge empty space at the bottom of the Y Axis and just zoom into the relevant part of the graph. It seems as though the margins are still adjusted to the default min/max values of the underlying raw data (mainly at the bottom/lower values of the Y axis).

    Please can anyone please help me figure out how to manipulate these margins? I don't understand why the graph is produced this way.

    Than you!

    Catherine

  • #2
    stripplot is from SSC, as you are asked to explain (http://www.statalist.org/forums/help#stata 12.2).
    A recent reference is http://www.statalist.org/forums/foru...updated-on-ssc

    Googling for hours ranks with watching lots of videos as a problem-solving method of long duration and low efficiency.

    Some other strategies are

    1. Thinking about what the program is designed to do.

    2. Looking at the code to see what it does precisely.

    3. Active experiment with variants on the code to single out the root of the difficulty.

    #3 is easiest for learners.

    Here I am confident that

    Code:
    stripplot birthweight, over(year) vertical box(bfcolor(gs14) barw(0.2)) iqr(1.5) ms(none)
    will show the same problem. So, what is the same problem precisely? Specifying ms(none) means what it says and no more: the marker symbol is suppressed but Stata does not change the axis extent.

    You give no example data but a sequence like

    Code:
    sysuse auto, clear
    scatter mpg weight
    scatter mpg weight, ms(none)
    will make the point emphatic.

    I don't have a trivially easy solution for you. The purpose of stripplot is to show distributions! Adding an option to suppress the data point display is unnecessary because ms(none) provides that any way; adding an option to contract the range of the outcome axis to adjust for invisible points would be utterly contrary to my taste as the programmer concerned.

    I'd work with

    http://www.stata-journal.com/sjpdf.h...iclenum=gr0039

    http://www.stata-journal.com/sjpdf.h...lenum=gr0039_1

    to create your own boxes and whiskers and draw them directly. As you are smoothing 10 and 90% quantiles, I'd recommend showing those percentiles rather than whiskers based on 1.5 iqr.

    Comment


    • #3
      Thanks Nick - I recreated the graph by building each layer of it using "egen" and "twoway" commands, as described in your third link to the STATA Journal article. This allowed me to manipulate the Y axis in a way that isn't possible (or intended) with "stripplot".

      Your problem solving advice has been noted. I'll spend more time working through and understanding STATA documentation examples rather than Googling easy fixes to problems that I can avoid to begin with!

      Catherine

      Comment

      Working...
      X