ggplot2: 常用 theme

全白 主题:

+ theme(axis.line = element_blank(),axis.text = element_blank(),axis.ticks = element_blank(), panel.background = element_blank(), panel.grid = element_blank())

四面边框,白背景主题:

+ theme(panel.border = element_rect(colour = "black", fill = NA, linewidth = 1), axis.line = element_blank(), panel.background = element_blank(), panel.grid = element_blank())

四面边框,白背景,灰色网格主题:

+ theme(panel.border = element_rect(colour = "black", fill = NA, linewidth = 0.7), axis.line = element_blank(), panel.background = element_blank(), panel.grid.major = element_line(color = "grey90", linewidth = 0.2), panel.grid.minor = element_line(color = "grey90", linewidth = 0.2))




超全教程

https://zhuanlan.zhihu.com/p/463041897

1. 修改主网格线

theme(panel.grid.major=element_line(size=1.5, linetype =1, color="gray"))

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")+theme_bw()+
    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(plot.title = element_text(hjust = 0.5, size=25, color="red"))+
    theme(panel.grid.major=element_line(size=2, linetype =1, color="gray"))

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

2. 修改副网格线

theme(panel.grid.minor=element_line(size=1.5, linetype =1, color="gray"))

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")+theme_bw()+
    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(plot.title = element_text(hjust = 0.5, size=25, color="red"))+
    theme(panel.grid.minor=element_line(size=1.5,linetype =1,color="gray"))

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

3. 修改边框

theme_bw() + theme(panel.background = element_rect(size = 3, color = "black"))

注意:此修改要在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")+theme_bw()+
    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(plot.title = element_text(hjust = 0.5, size=25, color="red"))+
    theme(panel.background = element_rect(size = 4, color = "black"))

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

4. 修改轴须

theme(axis.ticks=element_line(size=2), axis.ticks.length=unit(1.5,"mm"))

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")+theme_bw()+
    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(plot.title = element_text(hjust = 0.5, size=25, color="red"))+
    theme(axis.ticks=element_line(size=4, color="red"), axis.ticks.length=unit(5,"mm"))

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

常用修改

theme_bw()+theme(panel.grid.major=element_line(size=1.5, linetype =1, color="gray"), 
          panel.grid.minor=element_line(size=1.5,linetype =1,color="gray"),
          panel.background = element_rect(size = 3, color = "black"),
          axis.ticks=element_line(size=2),
          axis.ticks.length=unit(1.5,"mm"))
theme(panel.background = element_rect(size = 2, color = "black"),
          axis.ticks=element_line(size=1),
          axis.ticks.length=unit(2,"mm"))
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容