gpt4 book ai didi

r - 如何在 R 中添加带有透视图的颜色条

转载 作者:行者123 更新时间:2023-12-01 21:54:34 25 4
gpt4 key购买 nike

可能做起来很简单,但是经过几个小时的搜索,我无法找到如何使用 R 在透视图旁边添加颜色条。有人可以帮忙吗?谢谢。

persp(w_lb, w_dti, cm[[i]], 
theta = -30, phi = 30, expand = 0.95,
col=color[facetcol], shade = 0.25,
ticktype = "detailed", border = NA,
xlab = "LB", ylab = "DT", zlab="CM",
zlim=c(0.0, 1.0)
)

最佳答案

可以使用 fields 包中的 image.plot 添加图例。使用 ?persp 中的示例:

library(fields)

## persp example code
par(bg = "white")
x <- seq(-1.95, 1.95, length = 30)
y <- seq(-1.95, 1.95, length = 35)
z <- outer(x, y, function(a, b) a*b^2)
nrz <- nrow(z)
ncz <- ncol(z)
# 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 <- (z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz])/4
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)
persp(x, y, z, col = color[facetcol], phi = 30, theta = -30, axes=T, ticktype='detailed')

## add color bar
image.plot(legend.only=T, zlim=range(zfacet), col=color)

编辑感谢@Marc_in_the_box:颜色条的范围由zfacet定义,而不是由z定义 persp with colorbar

关于r - 如何在 R 中添加带有透视图的颜色条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22652941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com