Recommend a scale colour for 13 or more categories
Asked Answered
B

1

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)

Boynton answered 28/11, 2012 at 23:51 Comment(1)
there is some discussion at #6075640Typology
T
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.

Tarsier answered 29/11, 2012 at 0:0 Comment(1)
Also led me to things like: scale_color_manual(values=c(brewer.pal(12,"Set3"),"#999999")) for example.Boynton

© 2022 - 2024 — McMap. All rights reserved.