Reputation: 666
I often work with plotting a lot of groups in R, and here, it can be useful to colortheme "groups of groups". So for example, with the named colors, I usually map colors something like this:
group 1a = "indianred1"
group 1b = "indianred4"
group 2a = "darkseagreen1"
group 2b = "darkseagreen2"
group 2c = "darkseagreen4"
However, i'd like to do that with any given color. There is, of course, webpages that allows one to do that, but that is too timeconsuming, and of course this can be archived inside R. My knowledge of colors theory just isn't good enough to do that.
This seems like an almost too simple question not to already been answered, but I tried looking around without success.
Edit: To further clarify my post:
I don't want to find the shades within two colors that are already defined, here I could use colorRamp, as PoGias suggedsted. What I want to archive is to 2 or more shades of one color. Say, I only have "steelblue", and Rs color palette didn't have the four shades: steelblue1,2,3,4. How do I go from steel blue, a single color, to many shades of that color.
Upvotes: 1
Views: 662
Reputation: 35392
You'll need to do some transformation of the color. You can't get a precise answer without a clear idea of what you want to vary. But one easy thing is to desaturate:
library(colorspace)
my_col <- "steelblue4"
my_col_desat <- desaturate(my_col)
pal <- colorRampPalette(c(my_col_desat, my_col))
Example use:
library(ggplot2)
ggplot(data.frame(x = runif(10), y = runif(10)), aes(x, y)) +
stat_density_2d(aes(fill = ..density..), geom = 'tile', contour = FALSE) +
scale_fill_gradientn(colours = pal(10))
Upvotes: 2