我正在尝试绘制一个三维频率图,工作正常。后来,我想为Z轴创建一个色阶。
我试过了:
intensity = seq(0,30, length=31)
colorscale = list(
c(0, 'rgb(0, 255, 0)'),
c(15, 'rgb(247,255,0)'),
c(30, 'rgb(255, 0, 0)')
)
p<-plot_ly(data = d_long, x = ~i_DiaAlerta, y = ~variable, z = ~value, type="mesh3d",
intensity = intensity,
colorscale = colorscale,
showscale = TRUE)
p
它产生了这个情节: Plot
色标错误,情节为白色 我的d_long图看起来像这样:
头(d_long)
i_DiaAlerta variable value
1 188 1 4
2 189 1 5
3 190 1 1
4 191 1 3
5 192 1 0
6 193 1 0
答案 0 :(得分:0)
您需要传递colors
参数:
d_long <- data.frame(
i_DiaAlerta = runif(30, min = 0, max = 30),
variable = runif(30, min = 0, max = 30),
value = runif(30, min = 0, max = 30)
)
p <- plot_ly(data = d_long, x = ~i_DiaAlerta, y = ~variable, z = ~value, type="mesh3d",
intensity = ~value,
colors = colorRamp(c(
rgb(0, 255, 0, max = 255),
rgb(247,255,0, max = 255),
rgb(255, 0, 0, max = 255)
)),
showscale = TRUE)
p