添加colorscale到plotly

问题描述 投票:1回答:1

我试图绘制3D地图的频率,其工作正常。后来,我想创建为Z轴的colorscale。

我尝试这样做:

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)

  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
r colors plotly
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.