10

The default scale for ggplot2 for 13 or more colours does not provide a high degree of visual differentiation. In addition, the longest of the brewer scales ends at 12 categories (Set3).

Can you recommend a colour scale that would be visually useful for 13 or more categories?

Reproducible example:

dat <- data.frame(value=rnorm(100),
category=sample(letters[1:13],100,replace=T),
other=sample(letters[1:5],100,replace=T))

# Default Scale
ggplot(dat, aes(other,value,color=category)) + 
geom_point(size=6) + 
coord_flip()

# Brewer Scale // notice the blank at the end!
ggplot(dat, aes(other,value,color=category)) + 
geom_point(size=6) + 
coord_flip() + 
scale_color_brewer(palette="Set3")

Note: facetting is not an option in my case (client doesn't like it, go figure)

Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
  • 2
    there is some discussion at http://stackoverflow.com/questions/6075140/in-r-how-do-i-change-the-color-value-of-just-one-value-in-ggplot2s-scale-fill-b/6076605#6076605 – Ben Bolker Nov 29 '12 at 00:13

1 Answers1

9

You could use colorRampPalette and scale_colour_manual to fudge a 13th category.

set3 <- colorRampPalette(brewer.pal('Set3',n=12))

ggplot(dat, aes(other,value,color=category)) + 
     geom_point(size=6) + 
     coord_flip() + 
     scale_color_manual(values = setNames(set3(13), levels(dat$category)))

This will break down, in that the colours will not be nicely distinguishable if you set the required numbers too high.

mnel
  • 113,303
  • 27
  • 265
  • 254