ggplot2: 自带背景和主题

1. theme_bw()

kk <- as.data.frame(list(aa=rnorm(1000), bb=rnorm(1000)))

plot_1 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+
    ggtitle("默认")+theme(plot.title = element_text(hjust = 0.5, size = 25, color="red"))
plot_2 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+theme_bw()+
    ggtitle("theme_bw()")+theme(plot.title = element_text(hjust = 0.5, size=25, color="red"))

plot_grid(plot_1, plot_2)   '#示例一
示例一

2. theme_linedraw()

kk <- as.data.frame(list(aa=rnorm(1000), bb=rnorm(1000)))

plot_1 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+
    ggtitle("默认")+theme(plot.title = element_text(hjust = 0.5, size = 25, color="red"))
plot_2 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+theme_linedraw()+
    ggtitle("theme_linedraw()")+theme(plot.title = element_text(hjust = 0.5, size=25, color="red"))

plot_grid(plot_1, plot_2)   '#示例二
示例二

3. theme_classic()

kk <- as.data.frame(list(aa=rnorm(1000), bb=rnorm(1000)))

plot_1 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+
    ggtitle("默认")+theme(plot.title = element_text(hjust = 0.5, size = 25, color="red"))
plot_2 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+theme_classic()+
    ggtitle("theme_classic()")+theme(plot.title = element_text(hjust = 0.5, size=25, color="red"))

plot_grid(plot_1, plot_2)   '#示例三
示例三

4. theme_cowplot()

kk <- as.data.frame(list(aa=rnorm(1000), bb=rnorm(1000)))

plot_1 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+
    ggtitle("默认")+theme(plot.title = element_text(hjust = 0.5, size = 25, color="red"))
plot_2 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+theme_cowplot()+
    ggtitle("theme_cowplot()")+theme(plot.title = element_text(hjust = 0.5, size=25, color="red"))

plot_grid(plot_1, plot_2)   '#示例四
示例四

5. theme_light()

kk <- as.data.frame(list(aa=rnorm(1000), bb=rnorm(1000)))

plot_1 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+
    ggtitle("默认")+theme(plot.title = element_text(hjust = 0.5, size = 25, color="red"))
plot_2 <- ggplot()+geom_point(data = kk, aes(x=aa, y=bb), stat = "identity", position = "dodge")+theme_light()+
    ggtitle("theme_light()")+theme(plot.title = element_text(hjust = 0.5, size=25, color="red"))

plot_grid(plot_1, plot_2)   '#示例五
示例五
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 写在前面 ggplot2 是一个功能强大且灵活的R包 ,由Hadley Wickham 编写,其用于生成优雅的图...
    Boer223阅读 28,264评论 0 67
  • 简介 文章较长,点击直达我的博客,浏览效果更好。本文内容基本是来源于STHDA,这是一份十分详细的ggplot2使...
    taoyan阅读 51,425评论 7 159
  • ggplot2绘图时首先确定数据如何展示,然后再用主题系统对细节进行渲染。主题系统包括绘图区的背景、网格线、坐标轴...
    zjh9280阅读 741评论 0 1
  • ggplot2画图的时候有几个默认主题,画图的时候我们可以自己挑选一个喜欢的内置主题,也可以自己设置。其中内置主题...
    生信编程日常阅读 951评论 0 5
  • !备忘,方便自己查询,随着使用更新,无参考价值。 Function reference[https://ggplo...
    shwzhao阅读 988评论 0 7