Reputation: 119
I would like to use a diverging palette similar to "RdYlBu" in the RColorBrewer Package for coloring the points of a scatter plot. 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.
I am able to generate the plot using "RdYlBu" using the following specification:
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?
I really tried researching this for a long time and found lots of interesting things about colors, but nothing that addresses my specific question.
Upvotes: 2
Views: 987
Reputation: 42592
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....#)
You wanted
#first five values of RdYlBu#, "Green", #last 5 five values of "RdYlBu"#
head(x, 5)
will get the first 5 elements of vector x
, tail(x, 5)
the last 5 elements. Concatenate the pieces with c(...)
and you're done.
Upvotes: 4