简体   繁体   中英

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. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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