如何在R-Plotly等高线图中手动设置色阶?

时间:2019-03-14 13:47:35

标签: r r-plotly

我正在尝试在轮廓图中设置Rainbow色标,但不知道该怎么做。我这样启动代码:

p = plot_ly(type = 'contour', z = matrix, 
    x = fracao, y = -prof, colorscale = 'Rainbow', 
    autocontour = F, contours = list(start = 0, end = 12, size = 3, showlabels = T))
    %>% colorbar(title = "Wt. %"))

但是在阅读了本主题之后... Colorscale = 'Rainbow' in plot_ly doesn't work

我将代码更改为:

    p = plot_ly(type = 'contour', z = matrix, 
    x = fracao, y = -prof, colorscale = cbind(seq(0, 1, by=1/(length(z) -1)), rainbow(length(z))), 
    autocontour = F, contours = list(start = 0, end = 12, size = 3, showlabels = T))
    %>% colorbar(title = "Wt. %"))

问题是,尽管我的绘图有一个“彩虹”调色板,但它看起来并不好,如下所示: enter image description here

如何设置与该图相似的色阶(?): enter image description here

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决问题的方法...非常简单:

colorscale = list(c(0, 0.5, 1), c('blue', 'yellow', 'red'))

您可以添加更多间隔(0、0.2、0.4 ...),并根据需要将颜色字符串名称更改为rgb或HTML。

相关问题