Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
标准化色标,面板中的persp()绘图,R_R_Plot_Colors_3d - Fatal编程技术网

标准化色标,面板中的persp()绘图,R

标准化色标,面板中的persp()绘图,R,r,plot,colors,3d,R,Plot,Colors,3d,我正在创建一个包含多个persp图的面板,每个图显示通过在复杂回归模型中调整预测变量生成的一系列数据。我希望我的3D曲面通过我的z变量进行颜色编码,我可以很容易地做到这一点。如何使用此色标并使其覆盖面板中所有绘图所代表的所有z变量值的范围,以便可以比较多个persp绘图之间的色标 #colorized z scale, only a smidge modified from http://www.inside-r.org/r-doc/graphics/persp par(bg = "white"

我正在创建一个包含多个persp图的面板,每个图显示通过在复杂回归模型中调整预测变量生成的一系列数据。我希望我的3D曲面通过我的z变量进行颜色编码,我可以很容易地做到这一点。如何使用此色标并使其覆盖面板中所有绘图所代表的所有z变量值的范围,以便可以比较多个persp绘图之间的色标

#colorized z scale, only a smidge modified from http://www.inside-r.org/r-doc/graphics/persp
par(bg = "white")
par(mfrow=c(1,2))
x <- seq(-1.95, 1.95, length = 30)
y <- seq(-1.95, 1.95, length = 35)
z1 <- outer(x, y, function(a, b) a*b^2)
nrz <- nrow(z1)
ncz <- ncol(z1)
# Create a function interpolating colors in the range of specified colors
jet.colors <- colorRampPalette( c("blue", "green") )
# Generate the desired number of colors from this palette
nbcol <- 100
color <- jet.colors(nbcol)
# Compute the z-value at the facet centres
zfacet <- z1[-1, -1] + z1[-1, -ncz] + z1[-nrz, -1] + z1[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)
persp(x, y, z1, zlim=c(-8, 10.5), col = color[facetcol], phi = 30, theta = -30)
#zlim added to encompass combined ranges of z1 and z2

#exact same code, with different values of z
x <- seq(-1.95, 1.95, length = 30)
y <- seq(-1.95, 1.95, length = 35)
z2 <- outer(x, y, function(a, b) a*b^2+3)
nrz <- nrow(z2)
ncz <- ncol(z2)
# Create a function interpolating colors in the range of specified colors
jet.colors <- colorRampPalette( c("blue", "green") )
# Generate the desired number of colors from this palette
nbcol <- 100
color <- jet.colors(nbcol)
# Compute the z-value at the facet centres
zfacet <- z2[-1, -1] + z2[-1, -ncz] + z2[-nrz, -1] + z2[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)
persp(x, y, z2, zlim=c(-8, 10.5), col = color[facetcol], phi = 30, theta = -30)
#zlim added to encompass combined ranges of z1 and z2

#comparing the values, we see that there's different, overlapping scales from z1 and z2
summary(as.vector(z1))
summary(as.vector(z2))
#彩色z刻度,仅从http://www.inside-r.org/r-doc/graphics/persp
标准杆(bg=“白色”)
par(mfrow=c(1,2))

x您可以在切割之前连接z值的两个向量(矩阵),然后在指定颜色时参考结果(切割)向量的相关子集

color <- jet.colors(nbcol)
z1facet <- z1[-1, -1] + z1[-1, -ncz] + z1[-nrz, -1] + z1[-nrz, -ncz]
z2facet <- z2[-1, -1] + z2[-1, -ncz] + z2[-nrz, -1] + z2[-nrz, -ncz]
facetcol <- cut(c(z1facet, z2facet), nbcol)
persp(x, y, z1, zlim=c(-8, 10.5), 
      col=color[facetcol[seq_along(z1facet)]], 
      phi=30, theta=-30)
persp(x, y, z2, zlim=c(-8, 10.5), 
      col=color[facetcol[-seq_along(z1facet)]], 
      phi=30, theta=-30)

根据需要调整
屏幕
距离
,以获得所需的外观,例如:

wireframe(z ~ x + y|g, data=dat, drape=TRUE, col.regions=color, 
          screen=list(z=30, x=-60), distance=0.5)

这太棒了!非常感谢。
wireframe(z ~ x + y|g, data=dat, drape=TRUE, col.regions=color, 
          screen=list(z=30, x=-60), distance=0.5)