I’ve been working with some basic plots to visualize some time series data in one of my projects. I’ve always had a hard time recalling exactly how to take things beyond the simple plot default settings so here are some useful links that I’ve found that were quite helpful.
First, the tried and true Quick-R site, for creating a y-axis on the right side of your plot (using side=):
Next this R-bloggers post on creating a multiple y-axes:
Then there is this link from Revolutions that contains some very useful information about resolution for output:
Lastly, synthesizing information from the r-bloggers link I have found VERY useful the use of the pretty function to help customize the tick marks on any axes (with the help also of ylim). I’ll cut and paste some code directly, and hopefully you can get the gist (understanding that the code snippet is very much out of context):
par(mar=c(5, 5, 4, 4) + 0.1) ylimit = c(0, (max(eventbymon$eventcount.sum))+0.25*(max(eventbymon$eventcount.sum))) plot(eventbymon$Eligibility.Date, eventbymon$eventcount.sum, type="l", yaxt="n", ylab="", lty=3, ylim = ylimit, xlab="Month", cex.lab=1) axis(4, <strong>at=pretty(ylimit))</strong> mtext("Events(n)", side=4, line=3, cex=1,las=0) title(main=paste(pers,"Events by Month for", coh, "for",year), cex.main=1.1) par(new=T) ylimit = c(min(eligbymon$Eligibility.Date.length)/1.05, (max(eligbymon$Eligibility.Date.length))) plot(eligbymon$Eligibility.Date, eligbymon$Eligibility.Date.length, type="l", ylim=ylimit, ylab="Eligibility (n)", xlab="", cex.lab=1) legend("bottomright",legend=c("Eligibility","Events"),lty=c(1,3), cex=0.85, inset=.025)