[R] How to do a pretty panel plot?
Ajay Shah
ajayshah at mayin.org
Thu May 14 22:51:26 CEST 2009
The pretty picture that I saw at:
http://chartsgraphs.wordpress.com/2009/02/09/r-panel-chart-beats-excel-chart/#more-1096
inspired me to try something similar. The code that I wrote is:
------snipsnip---------------------------------------------------------------------
M <- structure(list(date = structure(c(13634, 13665, 13695, 13726,
13757, 13787, 13818, 13848, 13879, 13910, 13939, 13970, 14000,
14031, 14061, 14092, 14123, 14153, 14184, 14214, 14245, 14276,
14304, 14335), class = "Date"), cospi = c(1987.31, 2033.37, 2140.13,
2120.66, 2427.09, 2917.7, 2915.28, 3262.06, 2616.26, 2617.75,
2277.69, 2538.13, 2374.09, 1911.22, 2063.73, 2081.28, 1813.58,
1304.96, 1219.73, 1361.74, 1299.2, 1242.74, 1339.18, 1557.29),
cospi.PE = c(19.2, 19.69, 20.13, 24.08, 27.61, 30.9, 30.69,
34.92, 26.95, 27.63, 23.86, 26.14, 23.72, 19.5, 23.43, 23.73,
20.69, 16.4, 16.12, 18.04, 18.46, 18.86, 20.24, 23.53)), .Names = c("date",
"cospi", "cospi.PE"), row.names = 209:232, class = "data.frame")
par(mfrow=c(2,1)) # try to get two plots, one above the other
plot(M$date, M$cospi, type="l", col="darkgrey", log="y",
xaxs="i", yaxs="i", axes=FALSE,
ylab="Cospi level")
axis(1, col="lightgrey", at=NULL, labels=FALSE)
axis(2, col="lightgrey", labels=TRUE)
plot(M$date, M$cospi.PE, type="l", col="darkgrey", log="y",
xaxs="i", yaxs="i", axes=FALSE,
ylab="Cospi P/E")
axis(2, col="lightgrey", at=NULL, labels=TRUE)
axis(1, col="lightgrey", at=NULL, labels=TRUE)
------snipsnip---------------------------------------------------------------------
and this is clearly all wrong.
* It's supposed to look like one rectangle inside which are two
plots. Instead it looks like two separate plots.
* The x axis is Dates and the axis labelling doesn't get that.
How do I set about making a pretty panel plot of these two series,
both of which share a common time axis?
--
Ajay Shah http://www.mayin.org/ajayshah
ajayshah at mayin.org http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.
More information about the R-help
mailing list