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

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

我正试图在我的轮廓图中设置彩虹色标,但不知道该怎么做。我开始这样的代码:

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

r r-plotly
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.