Some graphics defaults that I dislike

The discussion here of graphics defaults inspired me to collect this list of defaults in R graphics that I don’t like. In no particular order:

– Axes that extend below 0 or above 1
– Tick marks that are too big. They’re ok on the windows graphics device, but when I make my graphs using postscript(), I have to set tck=-.02 so that they’re not so big.
– Axis labels that are too far from the axes
– Axis numbers that are spaced too closely together
– A horrible system of cryptic graphics parameters (“mgp”, “mar”, “xaxs”, “xaxt”, etc)
– Too much space on the outside of the graph. This becomes a real problem when many graphs are put on the page. This can be corrected using mar, but it’s a pain, and lots of people don’t know about this and just use the default settings (which is why bad defaults are a problem).

I’m sure I could make my own functions to do this but I haven’t ever gotten around to doing this; I just copy code from old examples.

There are also things that I have to do by hand but should be done automatically (yes, I know that means I should write my own functions . . .), in particular, labeling individual lines directly on a graph rather than with a legend.

P.S. Yes, I know R is free so I shouldn’t complain . . .

9 thoughts on “Some graphics defaults that I dislike

  1. Similar to correcting space around the graph using "mar", I also find it cumbersome to try to change the default plot area, especially when doing multiple plots on one page. It often creates wide and short charts (if stacked top to bottom) or narrow and long charts (if stacked left to right).

    The aspect ratio on the set of graphs I just put up on my blog is horrible and should be used as an example of what not to do. (Just like R, the blog is free and so I didn't bother fixing it.)

  2. Or, you could release some R code to put in the startup that would set improved defaults, because I imagine that some people agree with you.

  3. I suppose this is the problem with such an open and flexible system. There are many times when we wish it just did what we want. But, then what we want may be different from what other people want. So, I like the idea of optional variable types for those of us who would find it useful. And, ideally, we'd work to make it easier to customize. I'm thinking about how one can use grep -R or grep –recursive . Perhaps R could have long and short forms for graphical parameters to make it more literate and self-explanatory for those who would prefer more self-explanatory code?

    BTW, at this point to avoid extra space, and squashed plots, I nearly always use this call before plotting:

    <pre>
    par(oma=c(0,0,0,0), ##to get rid of extra outside space unless I need mtext(outer=TRUE, …) later
    mar=somethingreasonable,
    mgp=c(1.5,.5,0), ##to make axis labels close to the axis
    pty="s") ##to prevent squashed plots
    </pre>

    Some times I have to fiddle with the actual width and height of the graphics device (i.e. pdf(file="blah.pdf",width=8,height=4) to keep the outside space to a minimum. Even with these precautions, before publication I tend to have to remove the extra space by hand either using gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox and cutting and pasting into the postscript file or using Illustrator to crop the file. The call to gs and editing of the .eps file probably could be/ought to be scripted.

    Speaking of arcane graphical parameters in R: What I'd like to see (and upon which I just wasted too much time, to no avail) is a way to use the srt parameter for text rotation in the text() function to plot text on regression lines roughly parallel to the line. I'm thinking of the "text on a path" feature in Illustrator. Perhaps we wouldn't want too much really curvy text on our plots, but labeling lines on the plots where the lines are close together can be a pain to do if the text cuts across other lines.

  4. – Axes that extend below 0 or above 1

    There's a very good reason for extending the scale-lines somewhat. See figure 2.9, page 32 in Cleveland's The Elements of Graphing Data.

    Anyway, you *can* change this, by using xaxs="i" and/or yaxs="i".

    – Tick marks that are too big. They're ok on the windows graphics device, but when I make my graphs using postscript(), I have to set tck=-.02 so that they're not so big.

    I don't see this difference, so I'm not sure what to answer here. But generally, I find the best way to create figures of inclusion in documents is to use setps() in the Hmisc package. For R >= 2.7.0, the built-in setEPS() might be a good alternative.

    – Axis labels that are too far from the axes

    I haven't thought about this, but you're right. The simplest solution is to use xyplot from the lattice package or qplot from the ggplot2 package, that don't have this problem. Using these packages instead of the old plotting functions is a good idea in any case. There is a reason the new grid system was created; use it.

    – Axis numbers that are spaced too closely together

    I don't observe this problem. Generally, I find R excellent in using sensible axis numbers (which is really non-trivial to do in an automatic fashion).

    – A horrible system of cryptic graphics parameters ("mgp", "mar", "xaxs", "xaxt", etc)

    Agreed! It's a legacy from S-Plus, I guess.

    – Too much space on the outside of the graph.

    This won't be a problem for single figures (where you will probably shrink to bounding box anyway). For multiple figures, it is a problem, but in those cases you really should use lattice or ggplot2.

    in particular, labeling individual lines directly on a graph rather than with a legend.

    As someone else mentioned, use labcurve.

  5. This is an amazing discussion. Everybody can add his/her own workaround. Some only use "standard fixes" others put them into the start-up file, and some even create or use yagpr (yet another graphics package for R).

    The sad thing though, is that these tiny glitches of bad defaults seem to finally draw all the remaining attention on the data analysis problem the graphics should eventually support, towards technical details that are irrelevant for the initial problem.

    Isn't it time to "de-babelize" R-graphics altogether?

  6. Thanks for all the comments. In reply:

    John and Seth: I guess I could put these defaults into the "arm" package. I've just never sat down and collected them. Every time I do a graph, I just find some other graph I've done that looks like I want things to look, and I tweak its code.

    Jake: I like the idea of names that are less cryptic than mar, cex, pty, etc.

    Gregor and Hadley: Yes, I should try to learn these. I did once learn the function that made a grid of plots–maybe it was lattice()?–but it was so confusing that I forgot it again.

    Karl: Yes, Cleveland is my hero, but I think the key is to distinguish between the "range of the data" and the "possible range of the data" (i.e., the "range of the sample space"). And then there's the range of the plot itself. plot() in R works with the range of the data, and the range of the plot, but not the range of the sample space.

    I agree that picking axis numbers is not easy. My own taste is to have smaller tick marks and fewer intervals but I have no particular evidence that my taste is better than the defaults.

    OK, OK, I'll learn the new grid system!

Comments are closed.