R:表面图中特定值的中心色标

时间:2017-05-05 11:06:34

标签: r plot 3d

我使用函数persp在R中制作3D表面图。在this questionthis thread的帮助下,我根据persp文档启发了以下可重现的示例:

# Load packages
library(dplyr)
library(RColorBrewer)

# Import and adjust data
data(volcano)
z <- volcano[1:50, 1:50]    # Cut matrix
z <- (z - 100)/10           # Rescale z-values
x <- 10 * (1:nrow(z))       # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z))       # 10 meter spacing (E to W)

# Create a function interpolating colors in the range of specified colors
jet.colors <- colorRampPalette(rev(brewer.pal(11, "RdBu")))

# Generate the desired number of colors from this palette
nbcol <- 50
color <- jet.colors(nbcol)

# Compute the z-value at the facet centres
zfacet <- z[-1, -1] + z[-1, -ncol(z)] + z[-nrow(z), -1] + z[-nrow(z), -ncol(z)]

# Recode facet z-values into color indices
facetcol <- ntile(zfacet, nbcol)

# Plot
p <- persp(x, y, z, col = color[facetcol], theta = 230, phi = 25, ticktype = 'detailed')
lines(trans3d(c(max(x), max(x), min(x), min(x), max(x)),
              c(max(y), min(y), min(y), max(y), max(y)),
              c(1, 1, 1, 1, 1), p),
      col = "blue")

Here is a link得到的3D图。

如您所见,色标从蓝色变为白色再变为红色。目前白色以4为中心。

假设我希望比例在1左右居中(因此1将是白色,而较大/较小的值将是红色/蓝色),这由框周围的蓝线显示。如何调整刻度中表示为白色的值?

0 个答案:

没有答案