R语言可视化——ggplot2包的八种默认主题及其扩展包

0引言

R语言中的ggplot2包里面的风格固定,在需要特殊的图形时,需要更改甚至自定义设置主题。本文展示ggplot2包里的八种默认的主题,并介绍扩展包ggthemes去自定义主题内容。

八种主题函数汇总表

主题函数效果
theme_bw()网格白色主题
theme_classic()经典主题
theme_dark()暗色主题,可用于对比
theme_gray()默认主题
theme_light()浅色坐标带网格
theme_linedraw()黑色网格线
theme_minimal()极简主题
theme_void()空白主题

主题汇总图

代码:

p1 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_bw() + 
labs(title = "网格白色主题")+  theme(legend.position = "none")
p2 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_classic() + 
labs(title = "经典主题")+  theme(legend.position = "none")
p3 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_dark() + 
labs(title = "暗色主题,可用于对比")+  theme(legend.position = "none")
p4 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_gray() + 
labs(title = "默认主题")+  theme(legend.position = "none")
p5 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_light() + 
labs(title = "浅色坐标带网格")+  theme(legend.position = "none")
p6 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_linedraw() + 
labs(title = "黑色网格线")+  theme(legend.position = "none")
p7 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_minimal() + 
labs(title = "极简主题")+  theme(legend.position = "none")
p8 <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, col = class, shape = class)) + 
theme_void()  + 
labs(title = "空白主题")+  theme(legend.position = "none")
grid.arrange(p1,p2,p3,p4,p5,p6,p7,p8, nrow=2)

在这里插入图片描述

扩展包

如果感觉上面的主题话没有你满意的可以去加载ggthemes包,里面会有更加个性化的参数,创作出你想要的主题。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

统计学小王子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值