[R] two questions about PLOT

Jim Lemon jim at bitwrit.com.au
Tue Jun 1 13:39:06 CEST 2010


On 06/01/2010 12:44 AM, Jie TANG wrote:
> here ,I want to plot two lines in one figure.But I have two problems
> 1) how to move one of the y-axis to be the right ? I tried to the
> command"axis(2)",But I failed.
> 2) how to add the axis information correctly.Since I have use the cmommand
> "axis(1,at=1:6,labels=gradeinfo$gradenam)"
>     but it seems that the correct information that I want is superposition
> with the old axis information.What can i do ?
> the script and figure is shown as below .thanks .:)
>
> outflnm<-paste(Outdic,"meansd.jpg",sep="/")
> jpeg(file=outflnm, bg="transparent")
> legend<-c("average error","stand quare error")
> lgcol<-c("black","red1")
> par(las=1)
> yylab<-c("forecast error")
> xxlab<-c("typhoon class")
> llty<-c(1,3)
> llwd<-c(4,4)
> #par(bg='yellow')
>
>
> plot(avegrp,type='l',lty=1,col='black',lwd=4,xlab=xxlab,ylab=yylab)
> par(new=T)
> plot(sdgrp,type='l',lty=3,col='red1',xlab=xxlab,ylab=yylab,lwd=4)
> #axis(2, col = "gold", lty = 2, lwd = 0.5)
> legend("topright", legend,   lty=llty, lwd=llwd,col =lgcol)
> axis(1,at=1:6,labels=gradeinfo$gradenam)
> dev.off()
>
Hi Jie,
First problem:

# put this just after the jpeg device is opened
# to leave extra space on the right
par(mar=c(5,4,4,4)
# then just before "dev.off"
axis(4,...)

Second problem:

# don't display the default x axis
plot(avegrp,type='l',lty=1,col='black',lwd=4,
  xlab=xxlab,ylab=yylab,xaxt="n")
# then display your custom axis

Jim



More information about the R-help mailing list