Ordered factors now viridis colors?

ggplot2

#1

It looks like in the new ggplot version 3 when you have an ordered factor the color is automatically viridis?

You can see the difference by uncommenting #d$group = as.character(d$group) in the code below.

With the change, if you don't want viridis now you have to use scale_color_manual and specify colors? That seems like a lot of work. Why not just leave the old colors?

The old way gave you default colors that were much more differentiated. Now with viridis it is hard to differentiate bars or points or whatever you are plotting.

Is scale color manual the only way around this? Seems like a ton of work every time you plot with ordered factors.


library(ggplot2)

d=data.frame(group= letters[1:4],v=1:4)

d$group = factor(d$group, levels= d$group, ordered = TRUE)

#d$group = as.character(d$group)

ggplot(d,aes(x = group, y =v,color =group,group = group))+geom_point()

#2

I've always preferred scale_color_brewer. You can tell it what type of scale to use: "seq"(uential), "div"(erging), or "qual"(itative). And then specify a nice palette by name. I'm partial to "Dark2" for qualitative data.


#3

Yep! So, basically you can use any scale_colour_*() you like (though obviously recommended best practices apply).

library(ggplot2)

d <- data.frame(group = letters[1:4], v = 1:4)

d$group <- factor(d$group, levels = d$group, ordered = TRUE)

ggplot(d, aes(x = group, y = v, color = group, group = group)) + 
  geom_point() +
  scale_color_brewer(type = "qual")

Created on 2018-09-26 by the reprex package (v0.2.1.9000)

If you want the old ones back, you can use:
https://ggplot2.tidyverse.org/reference/scale_hue.html