wangleihong的个人博客分享 http://blog.sciencenet.cn/u/wangleihong

博文

ggplot2,3.3.5 绘图主题与以前的2.2.* 版本有很大的区别

已有 2700 次阅读 2022-5-4 18:49 |系统分类:教学心得

library(ggplot2)
#2.2.*版以前的解说
# theme_grey(),线灰色的背景+白色的网格线

#theme_bw(), 白色背景+细灰色网格线
# theme_linedraw(), 白色背景+黑色的网格线,线有不同的宽度
# theme_light(),灰似linedraw 但有浅灰色的线条和坐标轴
# theme_dark(),与上一个很像,但是背景是暗色风格
# theme_minimal(), 简约风格主题,没有背景标注
# theme_classic(), 经典风格主题,没有x、y轴的线条和网格线
# theme_void(),完全是空白的主题

# 3.3.5版中,生成的各主题与上面的说法有一定的区别,比如,theme_grey() 并不是整个背景色是浅灰色+白色网格线,当绘制出置信区间一类的图件时,图件部分才显示出浅灰色+白色网格线。

举一例,一试

x <- rnorm(30,3,5)
y <- rnorm(30,5,10)
df <- data.frame(x,y)

base <- ggplot(df,aes(x,y))+geom_point(colour="blue",shape=1)

base+theme_grey()+ggtitle("theme_grey()")

上面的这个图上,是看不到浅灰色背景,也看不到白色网格线,下面绘一个拟合线,试试

base+geom_smooth(method="lm",se=TRUE)

上面这个图中,绘了拟合线,在置信区间内,明显可以看到浅灰色背景色,白色网格线。

有兴趣的同学不妨,试试主题 theme_bw(),theme_light(),theme_minimal(),绘制简单的图,如散点图,验证下能不能看到以前所讲的背景色+网格线了,但只要再加图层,且需要与白色背景区分时,主题特定的背景色+网格线才会出现。

base+theme_bw()+ggtitle("theme_bw()")
base+theme_linedraw()+ggtitle("theme_linedraw()")
base+theme_light()+ggtitle("theme_light()")
base+theme_dark()+ggtitle("theme_dark()")
base+theme_minimal()+ggtitle("theme_minimal()")
base+theme_classic()+ggtitle("theme_classic()")
base+theme_void()+ggtitle("theme_void()")



https://m.sciencenet.cn/blog-3509182-1337001.html

上一篇:科学调查与实验时,需要多少样本?
下一篇:LearnBayes计算后验,用ggplot2包绘图。

0

该博文允许注册用户评论 请点击登录 评论 (1 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-24 22:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部