[R] plot area: secondary y-axis does not display well
Muhammad Rahiz
muhammad.rahiz at ouce.ox.ac.uk
Fri Apr 2 12:12:02 CEST 2010
Dear useRs,
I'm having a slight problem with plotting on 2 axes. While the following
code works alright on screen, the saved output does not turn out as
desired i.e. the secondary y-axis does not display fully.
Just run the code and look at image output. Suggestions please...
thanks,
Muhammad
---
rm(list=ls())
x <- 1:100
y <- 200:300
par(mar=c(5,5,5,7)+0.1) # inner margin
par(oma=c(3,3,3,7)) # outer margin
png("image.png")
plot(x,cex=0.5,type="l",lty=2,pch=3,xlab="year",ylab="x-axis",las=1,col="blue")
par(new=TRUE)
plot(y,cex=0.5,type="l",lty=2,pch=3,xlab="",ylab="",las=1,axes=FALSE,ylim=c(0,500),col="red")
axis(4,las=1)
mtext("y-axis",side=4,line=3)
legend("topleft",col=c("blue","red"),lty=2,legend=c("x","y"),bty="n")
box("figure",col="red")
box("plot",col="blue")
dev.off()
More information about the R-help
mailing list