超全教程
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"))