Muhammad Rahiz
2010-Apr-02 10:12 UTC
[R] plot area: secondary y-axis does not display well
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()
Hi Muhammad, The problem is that you set the par() options before creating your png. I've tried, and it works if you do this: ... # x and y png("image.png") par(mar=c(5,5,5,7)+0.1) # inner margin par(oma=c(3,3,3,7)) # outer margin ... # rest of your code HTH, Ivan Le 4/2/2010 12:12, Muhammad Rahiz a ?crit :> 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() > > ______________________________________________ > 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. >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
Petr PIKAL
2010-Apr-02 11:00 UTC
[R] Odp: plot area: secondary y-axis does not display well
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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.