[R] How can I fit the secondary y axis legend on my graph?
Chris Grobler
bjorn.grobler at zoo.ox.ac.uk
Sun Sep 3 20:39:26 CEST 2006
Dear All,
Having a bit of trouble with plotting two y variables on the same
graph. I cannot manage to get the secondary y axis label on to the right
of the axis - it gets plotted beyond the graphic window I assume?! The
way I constructed the graph is thus:
plot(data[,3],data[,2],axes=F, type="b") ## plots my data from two
data colums without axes - fine
axis(1, at=data[,3]) ## adds my
primary axis - fine
mtext("Year", side=1, line=2) ## Adds the title
"Year" - fine
axis(2)
mtext("Index of population size", side=2, line=2) ## Puts the primary
y axis on and names it correctly
points(data[,3],data[,1],pch=16) ## puts my secondary y
points on - also fine
axis(4)
mtext("Number of sun hours in April", side=4, line=2) ## if I enter
"line=1" it writes over my inex numbers but if I put
"line=2" it disappears.
I assume that perhaps the graph automatically fills the space and does
not leave any for 'odd' axes. My questions therefore are: how can I get
the legend on that axis, how do I remove ylab and xlab to free the space
that they take (as they spaced by default at "line=3" and thus waste
space - I would like to set them to "line=2") and perhaps how do I
scrunch up the x-axis so that it leaves more space at either side?
Sorry for the ignorance!
Chris
More information about the R-help
mailing list