简体   繁体   English

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

[英]How to manually set the color scale in contour plots R-Plotly?

I'm trying to set a Rainbow color scale in my contour plot, but don't know how to do it. 我正在尝试在轮廓图中设置Rainbow色标,但不知道该怎么做。 I started my code like this: 我这样开始我的代码:

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. %"))

But after reading this topic... Colorscale = 'Rainbow' in plot_ly doesn't work 但是在阅读了本主题之后... plot_ly中的Colorscale ='Rainbow'不起作用

I changed my code for: 我将代码更改为:

    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. %"))

The problem is that although I got a "rainbow" palette for my plot, it doesn't look good, as you can see below: 问题是,尽管我的绘图有一个“彩虹”调色板,但看起来并不好,如下所示: 在此处输入图片说明

How can I set the colorscale of my plot similar to this one (?): 如何将绘图的色阶设置与此(?)相似: 在此处输入图片说明

Okay, I found how to resolve the problem... Quite simple: 好的,我找到了解决问题的方法...非常简单:

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

You can add more intervals (0, 0.2, 0.4...) and change the color string name to rgb or HTML if you want. 您可以添加更多间隔(0、0.2、0.4 ...),并根据需要将颜色字符串名称更改为rgb或HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM