Skip to content
Prev 44842 / 398503 Next

r: plots

Hallo

I use following function to produce graph of yright and yleft against x with 
additional options (like smoothing the lines, colour, line and point type choice and 
an options for some axes formating.


Cheers
Petr


#----------------------------------------------------------------------------------------------
# graf na 2 osach y

plot.yy<-function(x,yright,yleft, yleftlim=NULL, yrightlim = NULL, xlab = 
NULL ,yylab=c("",""),pch=c(1,2),col=c(1,2), linky=F, smooth=0, lwds=1, 
length=10, format="%d-%H:%M", ...)

{

par(mar=c(5,4,4,2),oma=c(0,0,0,3))
plot(x, yright, ylim=yrightlim, axes=F,ylab="", xlab=xlab, pch=pch[1],col=col[1], 
...)
axis(4,pretty(range(yright,na.rm=T),10),col=col[1])

if (linky) lines(x,yright,col=col[1], ...)

if (smooth!=0) lines(supsmu(x,yright,span=smooth),col=col[1], lwd=lwds, ...)

if(yylab[1]=="") 
mtext(deparse(substitute(yright)),side=4,outer=T,line=1, col=col[1], ...)
else 
mtext(yylab[1],side=4,outer=T,line=1, col=col[1], ...)

par(new=T)
plot(x,yleft, ylim=yleftlim, ylab="", axes=F ,xlab=xlab, pch=pch[2],col=col[2], ...)
box()
axis(2,pretty(range(yleft,na.rm=T),10),col=col[2], col.axis=col[2])

#if (is.null(class(x))) axis(1,pretty(range(x,na.rm=T),10)) else axis.POSIXct(1, x)

if (is.null(class(x))) axis(1,pretty(range(x,na.rm=T),10)) else 
{
l<-length(x)
axis(1,at=x[seq(1,l,length=length)],labels=format(as.POSIXct(x[seq(1,l,length=le
ngth)]),format=format))
}


#if (xDatum) 
axis(1,dates(pretty(range(datum,na.rm=T),10)),labels=as.character(chron(pretty(r
ange(datum,na.rm=T),10)),format=c("d/m/y")))
#else axis(1,pretty(range(x,na.rm=T),10))

if(yylab[2]=="")
mtext(deparse(substitute(yleft)),side=2,line=2, col=col[2], ...)
else
mtext(yylab[2],side=2,line=2, col=col[2], ...)


if (linky) lines(x,yleft,col=col[2], lty=2, ...)
if (smooth!=0) lines(supsmu(x,yleft,span=smooth),col=col[2], lty=2, lwd=lwds, 
...)

}
On 24 Feb 2004 at 14:44, allan clark wrote:

            
Petr Pikal
petr.pikal at precheza.cz