ggplot2的主题设置

作者: 生信编程日常 | 来源:发表于2019-12-22 16:20 被阅读0次

ggplot2画图的时候有几个默认主题,画图的时候我们可以自己挑选一个喜欢的内置主题,也可以自己设置。其中内置主题有以下几个,我们用iris数据集看一下效果:

  1. 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

image

3. theme_dark

image

4. theme_gray

image
  1. theme_light
image

6. theme_void

image
  1. theme_linedraw
image
  1. theme_minimal
image

如果要全局设置某一种主题的话,那么在开头写上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的主题设置

相关文章

网友评论

    本文标题:ggplot2的主题设置

    本文链接:https://www.haomeiwen.com/subject/dvmonctx.html