Seth W Bigelow
2008-Nov-24 16:35 UTC
[R] lattice contourplot background covers inward-facing ticks
I wish to have inward-pointing ticks on my contourplot graph, but the colored background produced by the "region=TRUE" statement covers the ticks up, is there any way around this? Sample code below. --Seth library(lattice) model <- function(a,b,c,d,e, f, X1,X2) # provide model function for contour plot {J <- a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2) pp <- exp(J)/(1+exp(J)) return(pp)} g <- expand.grid(X1= seq(0.3,0.9,0.001), X2 = seq(0.3,1, 0.001)) g$z <- model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # Create variable z using gridded data, model, and variables contourplot(z ~ X1 * X2, data = g, region = TRUE, # Adds color to background cuts = 10, # Number of contour intervals...(and color intervals!) scales = list(tck = c(-1,-1)) # ticks go inward ) ### END [[alternative HTML version deleted]]
Richard.Cotton at hsl.gov.uk
2008-Nov-24 17:14 UTC
[R] lattice contourplot background covers inward-facing ticks
> I wish to have inward-pointing ticks on my contourplot graph, but the > colored background produced by the "region=TRUE" statement covers the > ticks up, is there any way around this? Sample code below. --Seth > > library(lattice) > > model <- function(a,b,c,d,e, f, X1,X2) # provide model function> for contour plot > {J <- a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2) > pp <- exp(J)/(1+exp(J)) > return(pp)} > > g <- expand.grid(X1= seq(0.3,0.9,0.001), X2 = seq(0.3,1, 0.001)) > g$z <- model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # Create> variable z using gridded data, model, and variables > > contourplot(z ~ X1 * X2, > data = g, > region = TRUE, # Adds color to background > cuts = 10, # Number of contour intervals...(andcolor> intervals!) > scales = list(tck = c(-1,-1)) # ticks go inward > ) ### ENDThe easiest way is to make the contours semi-transparent by adding alpha.regions=0.7 (or whatever number you prefer) to the call to contourplot. This has a couple of poosible disadvantages though: 1. It will change the colours you used 2. You can't print to some devices (windows metafile isn't supported) Other solutions involve a lot of messing about. You could manually draw ticks using grid.xaxis (and grid.yaxis) in the grid package, or stop plotting to the edges of the panel. Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
baptiste auguie
2008-Nov-24 18:49 UTC
[R] lattice contourplot background covers inward-facing ticks
I believe you can simply modify the panel function to replot the axes on top with panel.axis(), library(lattice) model <- function(a,b,c,d,e, f, X1,X2) # provide model function # for contour plot {J <- a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2) pp <- exp(J)/(1+exp(J)) return(pp)} g <- expand.grid(X1= seq(0.3,0.9,0.01), X2 = seq(0.3,1, 0.01)) g$z <- model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # Create # variable z using gridded data, model, and variables contourplot(z ~ X1 * X2,panel=function(...){panel.levelplot(...); panel.axis("bottom", half = FALSE,labels=F) panel.axis("left", half = FALSE,labels=F) }, data = g, region = TRUE, # Adds color to background cuts = 10, # Number of contour intervals...(and color # intervals!) scales = list(tck = c(-1,-1)) # ticks go inward ) ### END Hope this helps, baptiste On 24 Nov 2008, at 16:35, Seth W Bigelow wrote:> I wish to have inward-pointing ticks on my contourplot graph, but the > colored background produced by the "region=TRUE" statement covers the > ticks up, is there any way around this? Sample code below. --Seth > > library(lattice) > > model <- function(a,b,c,d,e, f, X1,X2) # provide model > function > for contour plot > {J <- a + (b*X1) + (c*X2) + (d*X1*X2) + e*(X1^2) + f*(X2^2) > pp <- exp(J)/(1+exp(J)) > return(pp)} > > g <- expand.grid(X1= seq(0.3,0.9,0.001), X2 = seq(0.3,1, 0.001)) > g$z <- model(-29, -14, 52, 80, -3, -56, g$X1, g$X2) # > Create > variable z using gridded data, model, and variables > > contourplot(z ~ X1 * X2, > data = g, > region = TRUE, # Adds color to background > cuts = 10, # Number of contour intervals...(and > color > intervals!) > scales = list(tck = c(-1,-1)) # ticks go inward > ) ### END > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code._____________________________ Baptiste Augui? School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag