[R] Multi-figure plotting

Stefaan Lhermitte stefaan.lhermitte at agr.kuleuven.ac.be
Fri Nov 26 16:19:51 CET 2004


Dear R-ians,

I have a question concerning plotting different plots on one figure. I 
have written a script to plot an image, a legend (based on different 
rectangles) and a timeseries plot on one figure.
In my R-lagnuage it looks like this (without arguments that are not 
usefull for my question):

#---> I first define the functions
image.data<-function(...){
    ....
    #-->Plot the data
    par(fig=c(0,1,0.25,1),new=TRUE)
    par(pin=c(1.5,(num.y/num.x*1.5)))
    image(c(1:(num.x+1)),c(1:(num.y+1)),output.matrix,xlab="X 
coord",ylab="Y coord",main='NDVI',las =1,cex.axis=0.7, cex.lab=0.7, 
col=topo.colors(255), asp=1)

    #---> Add a legend (colored rectangles) + legend axis (=values)
    par(fig=c(0,1,0.3,0.4),new=TRUE)
    plot.window(xlim = c(0,1), ylim = c(0,1), yaxs="i")
    rect((1:254)/255,0,(2:255)/255,0.1,col=topo.colors(255),border=FALSE)
    axis(1,padj=-1,cex.axis=0.7)
    ...
}

profile.data<-function(...){
    ...
    #-->Plot the data
    par(fig=c(0,1,0,0.3),new=TRUE)
    par(pin=c(1.5,num.y/num.x*0.5))
    plot(NDVI, type="l",cex.axis=0.7, cex.lab=0.7)
    ...
}

When I subsequently use the functions I get problems with the legend. It 
plots my image nice in the upper part of  my pixture, adds the 
timeseries below, but it does not plot the rectangles of the legend. I 
don't know what I do wrong, because it plots perfectly the axis of the 
legend, but the colorbar is invisible. All suggestions would be wonderfull!

Thanx in advance,
Stef




More information about the R-help mailing list