当我们在使用 ggplot 时,使用分面通常会长下面这样(这里用 ggplot 的官方案例): p <- ggplot(mpg, aes(displ, hwy)) + ge
当我们在使用 ggplot 时,使用分面通常会长下面这样(这里用 ggplot 的官方案例):
p <- ggplot(mpg, aes(displ, hwy)) + geom_point()
p + facet_wrap(~class)
此时,我们想将背景的灰色底色去掉,可以用我们常用的 theme_bw()
:
p + facet_wrap(~class) + theme_bw()
此时如果背景的灰色网格不想要了,可以接着添加 theme(panel.grid = element_blank())
:
p + facet_wrap(~class) + theme_bw() +
theme(panel.grid = element_blank())
但此时我们是想纯白的背景,子标题中的灰色背景与标题边框也不需要了,此时可以在 theme()
函数中添加 element_rect()
,内部的参数 color = "white"
表示 子标题的周围边框变为白色;fill = "white"
表示子标题的灰色背景变为白色:
p + facet_wrap(~class) + theme_bw() +
theme(
strip.background = element_rect(
color = "white", fill = "white"),
panel.grid = element_blank())
这样看起来还是挺丑的,如果把每个画幅的一圈黑色边框去掉就更好了,此时可以添加 panel.border = element_blank()
:
p + facet_wrap(~class) + theme_bw() +
theme(
strip.background = element_rect(
color = "white", fill = "white"),
panel.grid = element_blank(),
panel.border = element_blank())
后面如果大家还想让整个图像变得更加清净,可以参考:R语言学习ggplot2绘制统计图形包全面详解
里面的 6. 零件打磨 部分。
以上就是R语言包ggplot实现分面去掉小标题的灰色底色小技巧的详细内容,更多关于ggplot分面去掉小标题灰色底色的资料请关注编程网其它相关文章!
--结束END--
本文标题: R语言包ggplot实现分面去掉小标题的灰色底色小技巧
本文链接: https://www.lsjlt.com/news/156596.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0