[R] Three questions about plotting

Jim Lemon jim at bitwrit.com.au
Fri Feb 28 04:03:49 CET 2014


On 02/28/2014 11:19 AM, David Parkhurst wrote:
> I would like to plot three graphs, one above the other, of three “y”
> variables that have different scales against a common Date variable, as
> with the code below.
>
> Q1. If I understand correctly, I can't use lattice graphics because my
> y's have different scales. Is that correct? All the lattice or trellis
> plots I've seen have common “y” scales for all plots.
>
> I have two problems with what this code produces:
> Q2. How can I get the vertical dimension of all three plots to be the
> same? I know that I've made them different by using different mar
> numbers, but I had to do that, I thought, to leave room for date axis
> labels. I don't want to leave wasted space between the plots.
>
You can get what you want with:

layout(matrix(1:3,ncol=1),heights=c(1,1,1.4))

rather than mfrow. Also, try using:

# first plot
par(mar=c(0,4,4,4))
# second plot
par(mar=c(0,4,0,4)) # and yaxt="n"
...
axis(4)
# third plot
par(mar=c(4,4,0,4))

> Q3. Why are my dates not coming out in the format I've specified in the
> axis.Date statement?
>
Try DateLbls<-format(seq.Date(...),format="%m-%y")

Jim




More information about the R-help mailing list