1

I have 24 groups that I have plotted using geom_line in ggplot2. I was wondering whether there is a quick way to change the colour of one of those particular groups to black without specifying the colours of the other 23?

My code:

ggplot(max, aes(x = dap,y = cf, group=variables, colour = variables)) +
                  geom_line(size=0.5) 
joran
  • 169,992
  • 32
  • 429
  • 468
user2726449
  • 607
  • 4
  • 11
  • 23
  • possible duplicate of [R: changing line colors with ggplot()](http://stackoverflow.com/questions/5171263/r-changing-line-colors-with-ggplot) – hrbrmstr Apr 09 '14 at 15:26
  • Yep - that is what I'm using... but I want to try and not specify the colours of every other group and just override the colour of just one. – user2726449 Apr 09 '14 at 15:31
  • 2
    If you know the order of the groups (they're factors, so it shld be easy to do that) then you can use `rep` to generate the vector of colors and just substitute one color in the position of the one you want to highlight. i.e. `line.cols <- rep("#7f7f7f",24) ; line.cols[4] <- "DIFFERENT"` – hrbrmstr Apr 09 '14 at 15:33
  • I could but I still want the other groups to be different colours. – user2726449 Apr 09 '14 at 15:42
  • 1
    `line.cols <- terrain.colors(24) ; line.cols[4] <- "DIFFERENT"` :-) or `rainbow` or `heat.colors` or `topo.colors` or `cm.colors` (and many outside `base` & `grDevices` packages. – hrbrmstr Apr 09 '14 at 15:46

0 Answers0