前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >R语言绘制靓图--ggthemr、gsci、tvthemes主题包

R语言绘制靓图--ggthemr、gsci、tvthemes主题包

作者头像
拴小林
发布2021-10-11 11:16:41
5880
发布2021-10-11 11:16:41
举报
文章被收录于专栏:数据驱动实践

1 ggthemr

一般情况下只会设置palette 参数,指定主题名称,其它均为默认参数【即每种主题的字号,磅值,图边距等均可修改】。

代码语言:javascript
复制
library(ggthemr)
options(repr.plot.width = 4.5, repr.plot.height = 3, repr.plot.res = 300)
ggthemr('grape')
ggplot(mpg, aes(manufacturer, hwy)) + 
  geom_boxplot() + 
  ggtitle('flat')+
  theme(axis.text.x = element_text(angle = 45))
  ggthemr_reset()
 
ggplot(mpg, aes(manufacturer, hwy)) + 
  geom_boxplot() + 
  theme(axis.text.x = element_text(angle = 45))
代码语言:javascript
复制
ggplot(mtcars, aes(mpg, disp, colour = factor(am))) +
    geom_point() +
    scale_colour_ggthemr_d()

flat

Base 16

flat dark

Base 16

camouflage

chalk

copper

grape

2 ggsci

代码语言:javascript
复制
install.packages("ggsci")
vignette("ggsci") # in R for a quick-start guide.
代码语言:javascript
复制
library("ggsci")
library("ggplot2")
library("gridExtra")

data("diamonds")

p1 = ggplot(subset(diamonds, carat >= 2.2),
       aes(x = table, y = price, colour = cut)) +
  geom_point(alpha = 0.7) +
  geom_smooth(method = "loess", alpha = 0.05, size = 1, span = 1) +
  theme_bw()

p2 = ggplot(subset(diamonds, carat > 2.2 & depth > 55 & depth < 70),
       aes(x = depth, fill = cut)) +
  geom_histogram(colour = "black", binwidth = 1, position = "dodge") +
  theme_bw()
  
  

2.1 NPG

代码语言:javascript
复制
p1_npg = p1 + scale_color_npg() + ggtitle("scale_color_npg()")
p2_npg = p2 + scale_fill_npg() + ggtitle("scale_fill_npg()")
grid.arrange(p1_npg, p2_npg, ncol = 2)

2.2 AAAS

代码语言:javascript
复制
p1_aaas = p1 + scale_color_aaas() + ggtitle("scale_color_aaas()")
p2_aaas = p2 + scale_fill_aaas() + ggtitle("scale_fill_aaas()")
grid.arrange(p1_aaas, p2_aaas, ncol = 2)

更多图片示例,请查看

代码语言:javascript
复制
vignette("ggsci") # in R for a quick-start guide.

3 tvthemes

代码语言:javascript
复制
#scale_fill_westeros
ggplot(mpg, aes(displ)) +
  geom_histogram(aes(fill = class), col = "black", size = 0.1) +
  scale_fill_westeros(palette = "Stannis", n = 7, reverse = TRUE) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  labs(title = glue("
                    We do not choose our destinies. 
                    Yet we must... we must do our duty, no? 
                    Great or small, we must do our duty."),
       subtitle = "I will have no burnings. Pray Harder.",
       caption = glue("
                      The Iron Throne is Mine by Right.
                      - Stannis Baratheon"),
       x = "Bent Knees", y = "Lightbringer") +
  theme_minimal() +
  theme(text = element_text(family = "Cinzel", size = 20),
        plot.title = element_text(family = "Cinzel", size = 26),
        plot.subtitle = element_text(size = 18),
        plot.caption = element_text(size = 16),
        axis.text = element_text(size = 18),
        legend.position = "none")
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-10-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 数据驱动实践 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 ggthemr
    • flat dark
      • camouflage
        • chalk
          • copper
            • grape
              • 3 tvthemes
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档