I'm using knitr 0.2, ggplot2 0.9.0 on Ubuntu 10.04.
In general I find that ggplot puts the axis titles a *little* closer
to the axis than I'd like (the opposite of base R's defaults, which are
almost always too far away), to the point where they sometimes overlap
labels depending on the exact plot size. I figured I could use the
'vjust' parameter to adjust this, but it looks like the text gets
clipped (!)
A few questions:
* does anyone have a theme/set of options setting that deals with this
in a general way? Maybe I should be trying to move the ylabel viewport
rather than adjust the position of the ylabel within the viewport?
* I was also going a bit crazy trying to figure out exactly how the
plot.margin() option works -- it seems based on trial and error (unless
I'm just confusing myself) that the 4th element in the margin vector
controls the left-hand margin (in base R this would be the 2d element in
the margin vector)?? Can someone point me to figures like those in
section 12 of the intro to R that illustrate the margin components for
base graphics?
Any advice appreciated.
Ben Bolker
Ben Bolker
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
Well, you should have to adjust anything - I'd rather fix this in base ggplot.
> * I was also going a bit crazy trying to figure out exactly how the
> plot.margin() option works -- it seems based on trial and error (unless
> I'm just confusing myself) that the 4th element in the margin vector
> controls the left-hand margin (in base R this would be the 2d element in
> the margin vector)?? Can someone point me to figures like those in
> section 12 of the intro to R that illustrate the margin components for
> base graphics?
I usually stick with the css ordering - top-right-bottom-left
(mnemonic: I always have TRouBLe remembering what order the elements
are in)
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
vjust = 0.32 looked reasonable to me after some trial and error.
The title spacing problem was fixed in 0.9.0, but of course that was
for the default font sizes. When the titles and axis labels are
magnified, all bets are off. I'm wondering if there's a way to code
themes so that when the font sizes are increased by a certain
magnitude, the plot background area is increased proportionally to
accommodate them. I'm not familiar enough with the code to know how
easy or hard that would be to do, though.
I played around with plot.margin = a little bit; all it does is pad
the total graphics region with white space. Play around with the
parameters and you'll find that it affects the size of the graph in
the document, shrinking it to accommodate the outside padding, but
doesn't really affect the rendering of the graph per se. Even with all
plot margins zero the y-axis title was still clipped at vjust = 0.25.
I think the relevant parameter in this problem is vjust because of the
size of the font.
Side note: knitr will save plots created within the document in the
same directory where the .Rnw file resides. If you want saved 7 x 7
plots, you should make fig.width and fig.height = 7 in the
\SweaveOpts{} chunk. It's also worth naming the code chunks because
the graphs will get saved with the name of the chunk. [chunk-name.dev,
where dev is the device specified.] In addition, you don't need
fig=TRUE in version 0.2; the argument has been deprecated and replaced
by fig.show and fig.keep. See the most recent documentation at the
knitr web site for details.
The document of mine to which Brandon referred doesn't use plot.margin
= anywhere, so that won't be of any help wrt this problem...but thanks
for the mention, Brandon :)
Dennis
Side note: knitr will save plots created within the document in the
same directory where the .Rnw file resides. If you want saved 7 x 7
plots, you should make fig.width and fig.height = 7 in the
\SweaveOpts{} chunk. It's also worth naming the code chunks because
the graphs will get saved with the name of the chunk. [chunk-name.dev,
where dev is the device specified.] In addition, you don't need
fig=TRUE in version 0.2; the argument has been deprecated and replaced
by fig.show and fig.keep. See the most recent documentation at the
knitr web site for details.
Dennis