1

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.

zx8754
  • 42,109
  • 10
  • 93
  • 154
emilBeBri
  • 538
  • 10
  • 15
  • Possible duplicate of [Gradient of n colors ranging from color 1 and color 2](https://stackoverflow.com/questions/13353213/gradient-of-n-colors-ranging-from-color-1-and-color-2) – pogibas Jan 27 '18 at 17:47
  • According to linked question: `colfunc – pogibas Jan 27 '18 at 17:48
  • No, I saw that. This is from *one' color, to many shades within that color. – emilBeBri Jan 27 '18 at 17:48
  • What do you mean? You can also do `colorRampPalette(c("steelblue1", "red"))` – pogibas Jan 27 '18 at 17:49
  • Okay, like this: I *don't* want to find the shades within two colors that are already defined. I want to find to 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. – emilBeBri Jan 27 '18 at 17:52
  • yes, well, that is possible I suppose. It seems like a bit of a "hack solution", though. There must be a more colortheoretically underpinned way to do it, a proper way to do it, so to speak. Hue, saturation, stuff like that. – emilBeBri Jan 27 '18 at 18:02
  • 2
    Regarding "shades [...] Hue, saturation, stuff like that", I think you need to be more clear which parameter(s) in which color space you wish to vary. – Henrik Jan 27 '18 at 19:00
  • I don't think so, no. It's not because I'm lazy, but my goal is clear, isn't it? I'm giving an example of what I want, that I don't posses the language to describe it is okay I think. – emilBeBri Jan 27 '18 at 20:50

1 Answers1

2

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

enter image description here

Axeman
  • 27,115
  • 6
  • 69
  • 82
  • Thank you for your time. However, this is not quite good enough to actually be useful, because the difference in colorshade is either: A) too close in the shade to the originial color or to be visually distinguable, or B) too grey and therefore not close enough to the original color. As stated, this is for use with discreet, not continous variables. For example: palette.tmp = colorRampPalette((c(desaturate("indianred"),"indianred")) palette = c(palette.tmp(6)[c(3,6)]) is not at all close to the difference between "indianred1" and "indianred4" – emilBeBri Jan 31 '18 at 13:22
  • As for the comment that "You can't get a precise answer without a clear idea of what you want to vary", I do not agree that I haven't done that: A way too create the same sort of difference in shade between for example "indianred1" and indianred4", where the starting point is "indianred" in itself. Just for any given color. It is correct that I don't know if the way to go about this is by adjusting the hue, saturation or something else, but the idea is pretty clear, I would say. Please correct me if you find this not to be the case. Again, thank you for your time :) – emilBeBri Jan 31 '18 at 13:26