[R] Odp: plot area: secondary y-axis does not display well

Petr PIKAL petr.pikal at precheza.cz
Fri Apr 2 13:00:45 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 02.04.2010 12:12:02:

> 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")

png device does not know about your margin settings. It was called 
**after** call to par. So put your

par(mar=c(5,5,5,7)+0.1) # inner margin
par(oma=c(3,3,3,7))    # outer margin

after call to png.

Regards
Petr

> 
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()
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list