简体   繁体   English

Rbrewer调色板的元素的颜色名称

[英]color names of elements of an Rbrewer palette

I would like to use a diverging palette similar to "RdYlBu" in the RColorBrewer Package for coloring the points of a scatter plot. 我想使用类似于RColorBrewer软件包中“ RdYlBu”的发散调色板为散点图的点着色。 However, I would like the middle color of the "RdYlBu" palette (the 6th color) to be "Green" and all other colors from the "RdYlBu" are just perfect. 但是,我希望“ RdYlBu”调色板的中间颜色(第六种颜色)为“绿色”,而“ RdYlBu”中的所有其他颜色都非常完美。

I am able to generate the plot using "RdYlBu" using the following specification: 我可以使用以下规范使用“ RdYlBu”生成图:

scale_colour_manual(values = brewer.pal(11,"RdYlBu"), name="Glc mmol/L", labels=c("<1.5", "1.5-2", "2-2.5", "2.5-3", "3-3.5", "3.5-5.5", "5.5-7.5", "7.5-10", "10-15", "15-20")) +

To get the same colors with the middle color (6th to be green), I believe I need to know the color "values" or names so that I can manually specify the colors. 为了获得与中间颜色(第六为绿色)相同的颜色,我相信我需要知道颜色的“值”或名称,以便可以手动指定颜色。 Something like this: 像这样:

scale_colour_manual(values = c(#first five values of RdYlBu#, "Green", #last 5 five values of "RdYlBu"#), #etc... etc....#)

My question is how can I find out what the values of the colors of RdYlBu are? 我的问题是如何找出RdYlBu的颜色值是多少?

I really tried researching this for a long time and found lots of interesting things about colors, but nothing that addresses my specific question. 我真的很努力地研究了很长时间,发现了很多关于颜色的有趣的东西,但是没有什么能解决我的特定问题。

You could try something along 你可以尝试一下

library(RColorBrewer)
br_pal <- brewer.pal(11,"RdYlBu")
my_pal <- c(head(br_pal, 5), "Green", tail(br_pal, 5))
# just for displaying old and new palette - not required for solution
scales::show_col(br_pal)
scales::show_col(my_pal)

scale_colour_manual(values = my_pal, #etc... etc....#)

Explanation 说明

You wanted 你自找的

#first five values of RdYlBu#, "Green", #last 5 five values of "RdYlBu"# #RdYlBu的前五个值#,“绿色”,#“ RdYlBu”的后五个值#

head(x, 5) will get the first 5 elements of vector x , tail(x, 5) the last 5 elements. head(x, 5)将获得向量x的前5个元素, tail(x, 5)获得后5个元素。 Concatenate the pieces with c(...) and you're done. c(...)将片段连接起来,就完成了。

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

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