Matching colors using multiple wireframes in R package lattice -
using syntax below managed have 2 wireframes in 1 plot (after interpolation). color schemes differ because based on range of z values (which different both z1 , z2). since in case z-axis between 0 , 1, match color gradients both plots. clarify, color gradient on right side of plot should between 0 , 1 (as z-axis) , not between minimum , maximum of z1 , z2 vector respectively.
can me out here?
library(lattice) library(akima) library(reshape2) x <- rep(c(5,10,15),4) y <- c(7,7,7,14,14,14,30,30,30,60,60,60) z1 <- c(0.17, 0.3,0.38,0.14,0.24,0.32,0.1,0.17,0.18,0.08,0.12,0.23) z2 <- c(0.63,0.7,0.76,0.66,0.73,0.79,0.72,0.79,0.83,0.76,0.82,0.88) interp_z1 <-melt(interp(x,y,z1)) flat_z1 <- interp_z1 [!is.na(interp_z1$var1)&!is.na(interp_z1$var2),] interp_z2 <-melt(interp(x,y,z2)) flat_z2 <- interp_z2 [!is.na(interp_z2$var1)&!is.na(interp_z2$var2),] points_z1<-data.frame(x=min(x)+(flat_z1$var1-1)/(40/diff(range(x))), y=min(y)+(flat_z1$var2-1)/(40/diff(range(y))), z=flat_z1$value) points_z2<-data.frame(x=min(x)+(flat_z2$var1-1)/(40/diff(range(x))), y=min(y)+(flat_z2$var2-1)/(40/diff(range(y))), z=flat_z2$value) wf_z1 <- wireframe(points_z1$z ~ points_z1$x + points_z1$y ,zlim = c(0,1) ,scales = list(arrows=false,cex=.7, tick.number = 4, z = list(arrows=f)) ,drape=t ,col.regions = rainbow(100, s = 1, v = 1, start = 0, end = max(1,100 - 1)/100, alpha = 1) ,screen = list(z = 60,x= -60) ,par.settings = list(box.3d = list(col=c(1,1,na,na,1,na,1,1,1)))) wf_z2 <- wireframe(points_z2$z ~ points_z2$x + points_z2$y ,zlim = c(0,1) ,scales = list(arrows=false,cex=.7, tick.number = 4, z = list(arrows=f)) ,drape=t ,col.regions = rainbow(100, s = 1, v = 1, start = 0, end = max(1,100 - 1)/100, alpha = 1) ,screen = list(z = 60,x= -60) ,par.settings = list(box.3d = list(col=c(1,1,na,na,1,na,1,1,1)))) library(gridextra) grid.arrange(wf_z1, wf_z2, ncol=2)
Comments
Post a Comment