参见:https://github.com/Mikata-Project/ggthemr

直接一步安装:

  1. devtools::install_github('Mikata-Project/ggthemr')

直接使用就好了:

  1. ggthemr('dust')
  2. # reset2default theme
  3. # ggthemr_reset()

为了防止颜色产生的bug :

在语句中添加 scale_colour_ggthemr_d()

  1. ggplot(mtcars, aes(mpg, disp, colour = factor(am))) +
  2. geom_point() +
  3. scale_colour_ggthemr_d()

使用模版

20. 用ggthemr 扩大你的主题库 - 图1

20. 用ggthemr 扩大你的主题库 - 图2

非常多,直接用就好了:

  1. > ggthemr()
  2. > ggthemr('flat dark')
  3. > ggplot(mtcars, aes(mpg, disp, colour = factor(am))) +
  4. + geom_point() +
  5. + scale_colour_ggthemr_d()

20. 用ggthemr 扩大你的主题库 - 图3

如果想要了解使用模版的配色方案,可以直接:

  1. > swatch()
  2. [1] "#555555" "#db735c" "#EFA86E" "#9A8A76" "#F3C57B" "#7A6752" "#2A91A2" "#87F28A" "#6EDCEF"
  3. attr(,"class")
  4. [1] "ggthemr_swatch"

用ggthemr 简单定制你的模版

其实也就是替换一下它的主题风格成你的颜色方案:

  1. # Random colours that aren't white.
  2. set.seed(12345)
  3. random_colours <- sample(colors()[-c(1, 253, 361)], 10L)
  4. ugly <- define_palette(
  5. swatch = random_colours,
  6. gradient = c(lower = random_colours[1L], upper = random_colours[2L])
  7. )
  8. ggthemr(ugly)
  9. example_plot + ggtitle(':(')

深度定制

这个不得不吹爆了。

你可以添加各种参数:

20. 用ggthemr 扩大你的主题库 - 图4

  1. > ggthemr('flat dark', layout = "clean")
  2. > ggplot(mtcars, aes(mpg, disp, colour = factor(am))) +
  3. + geom_point() +
  4. + scale_colour_ggthemr_d()

20. 用ggthemr 扩大你的主题库 - 图5

包括:

  1. layout # 各种布局风格
  2. # clean, claer, minimal, plain, scientific
  3. type # 图片类型,inner/outer,看背景与画布是否分离
  4. spacing # 坐标与坐标名称的距离,0,1,2,3

控制颜色亮度

  1. darken_swatch() / lighten_swatch(): darker/lighter swatch colours.
  2. darken_gradient() / lighten_gradient(): darker/lighter gradient colours.
  3. darken_palette() / lighten_palette(): darker/lighter everything.

使用部分模版

如果不想使用整个模版的内容,也可以单独的使用它们:

  1. example_plot + dust_theme$theme

20. 用ggthemr 扩大你的主题库 - 图6

20. 用ggthemr 扩大你的主题库 - 图7