Mikata-Project / ggthemr

Themes for ggplot2.
886 stars 107 forks source link

Cannot change swatch colors using ggthemr() #49

Closed orbitoo closed 3 years ago

orbitoo commented 3 years ago

Each time I use "ggthemr" to change my theme, I have to change the colors manually. It seems that function ggthemr() does nothing to colors. Here are my codes as an example.

library(ggplot2)
library(ggthemr)
ggthemr("chalk", "scientific")
ggplot(mpg, aes(displ, hwy, color = factor(cyl), shape = factor(cyl))) +
    geom_jitter() +
    geom_smooth(method = lm, formula = y ~ poly(x, 2)) +
    labs(shape = "cyl", color = "cyl")

Generates: Example1@4x

library(ggplot2)
library(ggthemr)
ggthemr("chalk", "scientific")
defaultColor <- swatch()[seq_len(swatch())]
ggplot(mpg, aes(displ, hwy, color = factor(cyl), shape = factor(cyl))) +
    scale_color_manual(values = defaultColor[2:5]) +
    geom_jitter() +
    geom_smooth(method = lm, formula = y ~ poly(x, 2)) +
    labs(shape = "cyl", color = "cyl")

Generates: Example2@4x