As a follow-up, I am able to achieve what I'd like to do in terms of a set range of values for amplitude using filled.contour() and specifying the zlim argument - however, in the end I'd still like to have the possibilities for layering that ggplot offers available to me; so, please let me know if you have ideas/solutions. Thanks
---------- e.g #assumes prior code in this thread was run to create sub1 and sub3 require(akima) zz1<-with(sub1, interp(x, y, amplitude)) zz3<-with(sub3, interp(x,y, amplitude)) filled.contour(zz1,col = topo.colors(24),xlab="x",ylab="x", zlim= c(0, 12000),main=one[1,4]) filled.contour(zz3,col = topo.colors(24),xlab="x",ylab="x", zlim= c(0, 12000),main=one[1,4]) On Thu, Feb 21, 2013 at 12:02 PM, Benjamin Caldwell <btcaldw...@berkeley.edu > wrote: > Dear R help, > > I have some readings in three dimensions (x, y, z) and an amplitude for > each. I'd like to visualize the data using ggplot, using tile plots, as I > have some additional point data I would like to eventually overlay on the > tile plots. > > I would like to subset the data by sections, slices if you will, in the z > dimension, and plot the data for that slice. > > I can do all of this, but am having a largish hangup - ggplot > automatically keys the fill gradient to the data which is assigned the fill > aesthetic. This is a problem for me because I have different ranges of > amplitudes for different depth slices. So, I'm seeing the same color > assigned to a different amplitude for each of my plots. > > I would like to assign the colors in the fill gradient to a range that I > specify, not the range that is in the subset of the data, but I don't know > how. > > Some example data and code attached. > > Thanks > > Ben Caldwell > > --------------------------------------------- > > require(ggplot2) > > setwd("") > > input<-read.table("examplefile.txt", header=TRUE) > str(input) > > head(input) > > # X x y z depth amplitude > # 1 1 0.0125 0.0125 -0.025 1 623 > # 2 2 0.0125 0.0375 -0.025 1 654 > # 3 3 0.0125 0.0625 -0.025 1 685 > # 4 4 0.0125 0.0875 -0.025 1 1598 > # 5 5 0.0125 0.1125 -0.025 1 2200 > # 6 6 0.0125 0.1375 -0.025 1 1917 > > depths<- with(input, sort(unique(depth))) > depths > # [1] 1 2 3 4 > > mysubset<-function(input, column.name, expression.to.match){ > > output <- input[column.name==expression.to.match,] > > return(output) > } > > sub1 <- mysubset(input, input$depth, depths[1]) > sub2 <- mysubset(input, input$depth, depths[2]) > sub3 <- mysubset(input, input$depth, depths[3]) > sub4 <- mysubset(input, input$depth, depths[4]) > > p <- ggplot(sub1, aes(x=x,y=y,fill=amplitude)) > p + geom_tile() + scale_fill_gradientn("Custom > Colours",colours=c("purple","blue","green","yellow","orange","red")) > # custom colours legend range and assigned colors is different than in the > next plot > > p <- ggplot(sub3, aes(x=x,y=y,fill=amplitude)) > p + geom_tile() + scale_fill_gradientn("Custom > Colours",colours=c("purple","blue","green","yellow","orange","red")) > > [[alternative HTML version deleted]] ______________________________________________ R-help@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.