ggplot2画图的时候有几个默认主题,画图的时候我们可以自己挑选一个喜欢的内置主题,也可以自己设置。其中内置主题有以下几个,我们用iris数据集看一下效果:
- theme_bw
data(iris)
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() + geom_smooth(method = 'lm') + theme_bw()
image
2. theme_classic
image3. theme_dark
image4. theme_gray
image- theme_light
6. theme_void
image- theme_linedraw
- theme_minimal
如果要全局设置某一种主题的话,那么在开头写上theme_set()即可:
# 比如设置theme_bw
theme_set(theme_bw())
如果不用内置的主题设置,或者我们想自己进行一些微调也是可以的, 只要修改theme()函数即可,如下所示:
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
这样可以让图片设置为方形,并且标题居中显示:
image删掉网格线并且背景颜色设置为白色:
ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
image
欢迎关注公众号~
ggplot2的主题设置
网友评论