[R-sig-eco] colorkey for image plots

Marcelino de la Cruz marcelino.delacruz at upm.es
Wed Feb 4 19:00:14 CET 2009


Maybe  image.plot in package fields could help you


Cheers,

Marcelino




At 17:45 04/02/2009, Glen A Sargeant wrote:
>If you can't figure out how to resolve the issue with optional arguments
>to a plotting function, you can copy and modify the plotting function
>itself.
>
>The component of code that creates legends for filled.contour() is a
>useful template and so is the snippet of my code, below, which is
>executable and creates a shaded bar showing progress of data collection.
>The 3 examples show that you can specify any colors or ordering you wish.
>
>foo <- function(colors){
>#For purposes of this example:
>N <- 100
>n <- 75
>
>#Display percent of plots completed in a
>   #bar at the bottom of figure
>   plot.new()
>   par(fig=c(0,1,0,0.5))
>   plot.window(c(0,1),c(0,1))
>
>
>   #N <- sum(progress$n.scheduled)
>   #n <- sum(progress$n.completed)
>   progress <- n/N
>   if(n>0){
>     breaks <- seq(0,progress,length=n+1)
>     xleft <- breaks[-(n+1)]
>     xright <- breaks[-1]
>     ybottom <- rep(0.75,n)
>     ytop <- rep(1,n)
>     col <- colors
>     rect(xleft,ybottom,xright,ytop,border=NA,col=col)
>   }
>   rect(0,0.75,progress,1)
>   rect(0,0.75,1,1)
>   mtext("Proportion completed")
>   axis(side=1,line=-4)
>   mtext(paste(n,"of",N,"plots completed"),side=1)}
>
>foo(heat.colors(n)[n:1])
>foo(heat.colors(n)[1:n])
>foo(terrain.colors(n)[n:1])
>foo(terrain.colors(n)[c(1:(n/2),n:(n/2+1))])
>
>*************************************************
>Glen A. Sargeant, Ph.D.
>Research Wildlife Biologist/Statistician
>Northern Prairie Wildlife Research Center
>8711 37th Street SE
>Jamestown, ND  58401
>
>Phone: (701) 253-5528
>E-mail:  glen_sargeant at usgs.gov
>FAX:     (701) 253-5553
>*************************************************
>
>
>
>From:
>Tomas <tdomingu at staffmail.ed.ac.uk>
>To:
>r-sig-ecology at r-project.org
>Date:
>02/04/2009 09:29 AM
>Subject:
>[R-sig-eco] colorkey for image plots
>Sent by:
>r-sig-ecology-bounces at r-project.org
>
>
>
>Hi
>I'm developing a model of leaf photosynthesis based on leaf nitrogen (N)
>and phosphorus (P). I've created a figure with a large range of possible
>combinations of N and P (x and y axes) with the outputs of my model as
>colors from the image function.
>I couldn't include on the figure a color key that would give the range
>of the model outputs. I tried other functions (filled.contour,
>levelplot, wireframe) but couldn't get around the need for ascending
>order of values.
>
>My code follows below. I'd appreciate any comments. Also, ideas on how
>to include a third leaf trait on this.
>
>Cheers,
>Tomas
>
>###################################
># figure with the variation of Vcmax with N and P
>
>rm(list=ls(all=TRUE))
>detach()
>
>##the libraries
>library(akima)
>library(stats)
>
>## the data
>data1 <- read.csv(file.name <- choose.files(),na.strings = "NA" , header
>= TRUE)
>attach(data1)
># the following prints the names of the variables from the dataset,
>check if file was correctly loaded
>names(data1)
>
>
>n<-seq(0,4,length=25)
>p<-seq(0,0.4,length=26)
>N<-rep(n,length(p))
>P<-rep(p,length(n))
>
>
>vn <- lm(Vcmax_Ci_area_25C~Narea_gm.2)
>vp <- lm(Vcmax_Ci_area_25C~Parea_gm.2)
>np<-lm(Narea_gm.2~Parea_gm.2)
>jn <- lm(Jmax_Ci_area_25C~Narea_gm.2)
>jp <- lm(Jmax_Ci_area_25C~Parea_gm.2)
>vnp <- lm(Vcmax_Ci_area_25C~Narea_gm.2*Parea_gm.2)
>
>
>
>#############################################################
># model of Vcmax_Ci_area_25C based on both N and P
>fitVJ <- function(x){
>                  a <- x[1]                               # variable 1
>(Intercept of Vcmax_Ci_area_25C~N.area.g.m-2)
>                  b <- x[2]                               # variable 2
>(Slope of Vcmax_Ci_area_25C~N.area.g.m-2)
>                  c <- x[3]                               # variable 3
>(Intersept of Vcmax_Ci_area_25C~P.area.g.m-2)
>                  d <- x[4]                               # variable 4
>(Slope of Vcmax_Ci_area_25C~P.area.g.m-2)
>                  e <- x[5]                               # variable 1
>(Intercept of Vcmax_Ci_area_25C~N.area.g.m-2)
>                  f <- x[6]                               # variable 2
>(Slope of Vcmax_Ci_area_25C~N.area.g.m-2)
>                  g <- x[7]                               # variable 3
>(Intersept of Vcmax_Ci_area_25CC~P.area.g.m-2)
>                  h <- x[8]                               # variable 4
>(Slope of Vcmax_Ci_area_25C~P.area.g.m-2)
>
>                  Vmodeled <- pmin((a+b*(Narea_gm.2)),(c+d*(Parea_gm.2)))
>                  Jmodeled <- pmin((e+f*(Narea_gm.2)),(g+h*(Parea_gm.2)))
>                  Vdiff <- sum(((Vcmax_Ci_area_25C) - Vmodeled)^2 +
>((Jmax_Ci_area_25C)
>- Jmodeled)^2)
>                  }
>guessvj <- c(coef(vn)[[1]],coef(vn)[[2]],
>coef(vp)[[1]],coef(vp)[[2]],coef(jn)[[1]],coef(jn)[[2]],
>coef(jp)[[1]],coef(jp)[[2]])
>g<- c(1,1,1,1,1,1,1,1)
>Fitv<- optim(guessvj,fitVJ,control = list (maxit =99000), method = "BFGS")
>
>V <- pmin((Fitv$par[1]+Fitv$par[2]*N),(Fitv$par[3]+Fitv$par[4]*P))
>V2 <- pmin((Fitv$par[5]+Fitv$par[6]*N),(Fitv$par[7]+Fitv$par[8]*P))
>
>
>par(mfrow=c(1,2))
>D1<-interp(P,N,V)
>image(D1,col = terrain.colors(50),xlim=c(0,0.35),ylim=c(0,3.9))
>title("Vcmax-modelled");title(xlab="Parea, g m-2"); title(ylab="Narea, g
>m-2")
>points(Narea_gm.2~Parea_gm.2)
>
>D2<-interp(P,N,V2)
>image(D2,col = terrain.colors(50),xlim=c(0,0.35),ylim=c(0,3.9))
>title("Jmax-modelled");title(xlab="Parea, g m-2"); title(ylab="Narea, g
>m-2")
>points(Narea_gm.2~Parea_gm.2)
>
>### end ###
>
>--
>The University of Edinburgh is a charitable body, registered in
>Scotland, with registration number SC005336.
>
>_______________________________________________
>R-sig-ecology mailing list
>R-sig-ecology at r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>
>
>         [[alternative HTML version deleted]]
>
>_______________________________________________
>R-sig-ecology mailing list
>R-sig-ecology at r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>
>---------------------------------------------------------------------------------------------------
>Texto añadido por Panda IS 2008:
>
>  Este mensaje NO ha sido clasificado como SPAM. 
> Si se trata de un mensaje de correo no 
> solicitado (SPAM), haz clic en el siguiente 
> vínculo para reclasificarlo: 
> http://localhost:6083/Panda?ID=pav_4157&SPAM=true&path=C:\Documents%20and%20Settings\mcr\Configuración%20local\Datos%20de%20programa\Panda%20Software\AntiSpam
>---------------------------------------------------------------------------------------------------

________________________________

Marcelino de la Cruz Rot

Departamento de  Biología Vegetal
E.U.T.I. Agrícola
Universidad Politécnica de Madrid
28040-Madrid
Tel.: 91 336 54 35
Fax: 91 336 56 56
marcelino.delacruz at upm.es



More information about the R-sig-ecology mailing list