项目地址:https://github.com/jrnold/ggthemes

这个包用起来非常简单,就像ggplot theme 中自带的主题一样。

简单使用

比如首先我们按照默认的主题方案画个:

  1. ggplot(chic, aes(x = date, y = temp)) +
  2. geom_point(aes(color = season), alpha = .3) +
  3. scale_color_tableau() +
  4. theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  5. labs(x = "Year", y = "Temperature (°F)")

19. 用ggthemes 丰富你的主题 - 图1

这时候我们可以加载themes 中提供的主题:

  1. p <- ggplot(chic, aes(x = date, y = temp)) +
  2. geom_point(aes(color = season), alpha = .3) +
  3. scale_color_tableau() +
  4. theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
  5. labs(x = "Year", y = "Temperature (°F)")
  6. p + theme_economist()

19. 用ggthemes 丰富你的主题 - 图2

直接就加上经济学人的风格啦~

还有一个比较出名的水墨风,Tufte’s plot:

  1. library(dplyr)
  2. chic_2000 <- filter(chic, year == 2000)
  3. ggplot(chic_2000, aes(x = temp, y = o3)) +
  4. geom_point() +
  5. labs(x = "Temperature (°F)", y = "Ozone") +
  6. ggtitle("Temperature and Ozone Levels During the Year 2000 in Chicago") +
  7. theme_tufte()

19. 用ggthemes 丰富你的主题 - 图3

各种主题如下:

  1. 主题名 描述
  2. theme_base 类似于 ggplot 默认设置
  3. theme_calc 类似 LibreOffice Calc 图表
  4. theme_economist 类似经济类图表
  5. theme_economist_white 类似经济类图表
  6. theme_excel 类似经典excel图表
  7. theme_few 简洁型
  8. theme_fivethirtyeight 类似于 http://fivethirtyeight.com的图
  9. theme_foundation 这个主题的设计是为了基础建立新的主题,而不是直接使用。theme_foundation是一个完整的主题,只有最小的元素定义。它相比于theme_graytheme_bw更容易通过扩展创建新的主题,因为那些主题和有着较深层次的主题定义。
  10. theme_gdocs 类似默认的 Google Docs Chart
  11. theme_hc Highcharts JS
  12. theme_igary 主题与白色面板和灰色背景。
  13. theme_map 一个简洁的地图主题
  14. theme_pander pander的默认主题
  15. theme_solarized 可以看 http://ethanschoonover.com/solarized 的介绍
  16. theme_solarized_2 同上
  17. theme_solid 主题删除所有non-geom元素(线条、文本等),这个主题只有所需的几何对象。
  18. theme_stata 基于 Stata graph schemes的主题
  19. theme_tufte 基于数据墨水最大化和图形设计的Edward Tufte 定量信息的视觉显示。没有边界,没有轴线,没有网格。这个主题与geom_ruggeom_rangeframe结合效果最好。
  20. theme_wsj Wall Street Journal theme
  21. ————————————————
  22. 版权声明:本文为CSDN博主「炫炫有牛腩」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
  23. 原文链接:https://blog.csdn.net/qq_27755195/article/details/52105087

给图例也配上颜色

这个theme 是只能修改主题,可以使用scalefill/color* 形式,修改图例颜色:

  1. p + theme_economist() + scale_color_calc(name = NULL)

19. 用ggthemes 丰富你的主题 - 图4