Xavier Bodin
2011-Feb-11 09:56 UTC
[R] Using filled.contour and contour functions together
Dear R help contributors, I'd like to plot ground temperature with time on X-axis and depth on Y-axis on this datasets ( http://r.789695.n4.nabble.com/file/n3301033/NEdaily.csv NEdaily.csv ), and to do so I use the following commands: library(RSEIS) xNE <- seq(1, as.numeric(as.Date(max(NEdaily[[1]])) - as.Date(min(NEdaily[[1]]))), 1) yNE <- rev(c(-0.3, -0.5, -0.7, -0.9, -1.1, -1.4, -1.7, -2, -2.5, -3, -4, -5, -7, -9, -10)) zNE <- mirror.matrix(as.matrix(NEdaily[1:(nrow(NEdaily)-1),2:length(NEdaily)])) filled.contour(xNE,yNE,zNE , col = myPal(20) , zlim = c(-20,20) , ylab = "Depth [m]", , xlab = paste("Days since ", as.Date(min(NEdaily[[1]]), format ="%d.%m.%Y")) ) contour(xNE,yNE,zNE, lty = 3, add = T) contour(xNE,yNE,zNE, nlevels = 1, level = 0, add = T, lwd = 1.5) I get this graph ( http://r.789695.n4.nabble.com/file/n3301033/NEdaily.png NEdaily.png ) and don't understand why filled.contour and contour plots are no set on the same dimensions and why they don't exactly overlay. Does anyone have an idea and a solution ?! Thanks in advance, Xavier -- View this message in context: http://r.789695.n4.nabble.com/Using-filled-contour-and-contour-functions-together-tp3301033p3301033.html Sent from the R help mailing list archive at Nabble.com.
You should start reading the documentation of the functions you use. ?filled.contour gives you the following: ...The output produced by |filled.contour| is actually a combination of two plots; one is the filled contour and one is the legend. Two separate coordinate systems are set up for these two plots, but they are only used internally - once the function has returned these coordinate systems are lost. If you want to annotate the main contour plot, for example to add points, you can specify graphics commands in the |plot.axes| argument. An example is given below. ... So you could use the example from the documentation to set up your own coordinate system. Or change the margins of the second plot so the two coordinate systems overlay ( par(mar=c()) ). I would use contourplot() in package lattice instead. HTH Jannis On 02/11/2011 10:56 AM, Xavier Bodin wrote:> Dear R help contributors, > > I'd like to plot ground temperature with time on X-axis and depth on Y-axis > on this datasets ( http://r.789695.n4.nabble.com/file/n3301033/NEdaily.csv > NEdaily.csv ), and to do so I use the following commands: > > library(RSEIS) > > xNE <- seq(1, as.numeric(as.Date(max(NEdaily[[1]])) - > as.Date(min(NEdaily[[1]]))), 1) > yNE<- rev(c(-0.3, -0.5, -0.7, -0.9, -1.1, -1.4, -1.7, -2, -2.5, -3, -4, > -5, -7, -9, -10)) > zNE<- > mirror.matrix(as.matrix(NEdaily[1:(nrow(NEdaily)-1),2:length(NEdaily)])) > > filled.contour(xNE,yNE,zNE > , col = myPal(20) > , zlim = c(-20,20) > , ylab = "Depth [m]", > , xlab = paste("Days since ", as.Date(min(NEdaily[[1]]), format > ="%d.%m.%Y")) > ) > contour(xNE,yNE,zNE, lty = 3, add = T) > contour(xNE,yNE,zNE, nlevels = 1, level = 0, add = T, lwd = 1.5) > > I get this graph ( http://r.789695.n4.nabble.com/file/n3301033/NEdaily.png > NEdaily.png ) and don't understand why filled.contour and contour plots are > no set on the same dimensions and why they don't exactly overlay. Does > anyone have an idea and a solution ?! > > Thanks in advance, > > Xavier[[alternative HTML version deleted]]
Xavier Bodin
2011-Feb-14 12:41 UTC
[R] Using filled.contour and contour functions together
Thanks to you, and to David Winsemius who replied, I finally found a solution, which works pretty fine : filled.contour(x,y,z, plot.axes = {axis(1); axis(2) ; contour(x,y,z2, add T); contour(x,y,z2, nlevels = 1, level = 0, add = T, lwd = 1.5)}) Xavier -- View this message in context: http://r.789695.n4.nabble.com/Using-filled-contour-and-contour-functions-together-tp3301033p3304904.html Sent from the R help mailing list archive at Nabble.com.