If you're mapping qualitatively to colour for a large number of groups, ggplot's automatic colour assignment plots very similar colours adjacently, making it hard to see which refer to which key etc. To illustrate:
require(ggplot2); require(stringr)
df = data.frame(x = letters, y = sample(20:100,26), lab=word("apple ball cat dog elephant frog goat hat ice jackal king lion mango nest owl parrot queen rabbit ship tomato umbrella van watch xylophone yatch zebra", 1:26))
p = ggplot(df, aes(x, y, fill=lab)) + geom_bar(stat="identity")
p + scale_fill_discrete()
Its possible to mix up some random colours manually:
cols = rainbow(26, s=.6, v=.9)[sample(1:26,26)]
p + scale_fill_manual(values=cols)
.. resulting in more useful breakup of the rainbow, but this seems clumsy, still leaves some colours clumped together and is generally not ideal. Does ggplot have a native method to achieve something like this (but hopefully better)?
rainbow(26, s=.6, v=.9)[sample(1:26,26)]
?