plot_ly mesh3d颜色无法正常工作

时间:2019-10-01 00:54:13

标签: r plotly

如何获得适合数字的色阶?最高点是2000,在这种情况下应为蓝色,但较高的值为红色,应为较低的数字。下面是一个示例数据框和代码。

test <- data.frame(a = c(10,20,15,30,45,40,20,30,25,30,10,40,10,20,15),
                   b = c(5,10,5,15,10,20,20,15,10,5,15,20,5,10,5),
                   c = c(500, 1000,1250, 750,575,200,800,2000,1500,1750,250,750,1000,800,500))

plot_ly(data = test,
        x = ~a,
        y = ~b,
        z = ~c,
        intensity = seq(0,2000, length = 8),
        colorscale = list(c(0,'rgb(255,0,0)'),
                          c(0.5, 'rgb(0,255,0)'),
                          c(1, 'rgb(0,0,255)')),
        type = 'mesh3d')

理想情况下,色阶会更加具体,其中0-500是红色,501-1000是橙色,1001-1500是黄色,1501-2000将是绿色(而不是刻度)。

1 个答案:

答案 0 :(得分:1)

也许这就是您需要的:

plot_ly(data = test,
        x = ~a,
        y = ~b,
        z = ~c,
        intensity = ~c,
        colorscale = list(c(0,'red'),
                          c(0.33,'orange'),
                          c(0.66, 'yellow'),
                          c(1, 'green')),
        type = 'mesh3d')

enter image description here