facet_wrap()和facet_grid()两个函数可以根据分类数据绘制一系列的子图,包括矩阵分面图、行分面图、列分面图。
library(RColorBrewer)
library(reshape2)
library(wesanderson)
p<-file.choose()
Alz <-read.csv(p, header = T)
ggplot(Alz, aes(x = tau, y = SOD, fill = Class)) +
geom_point(size=3,shape=21,colour="black") +
stat_smooth(method = "loess")+
facet_wrap( ~ Class) + #按class分面
theme(
strip.text = element_text(size=13,face="plain",color="black"), #控制分面标题的文字
text=element_text(size=12,face="plain",color="black"),
axis.title=element_text(size=14,face="plain",color="black"),
axis.text = element_text(size=11,face="plain",color="black"),
legend.position="none"
)
同样的图用face_grid()实现代码
ggplot(Alz, aes(x = tau, y = SOD,colour=Class, fill = Class)) +
geom_point(size=2,shape=21,fill="black",colour="black",alpha=0.5) +
stat_smooth(method = "loess")+
facet_grid(. ~ Class) +
theme(
strip.text = element_text(size=13,face="plain",color="black"),
text=element_text(size=12,face="plain",color="black"),
axis.title=element_text(size=14,face="plain",color="black"),
axis.text = element_text(size=11,face="plain",color="black"),
legend.position="none"
)
ggplot(Alz, aes(x = tau, y = SOD, fill= Class, size = age)) +
geom_point(shape=21,colour="black",alpha=0.7) +
facet_wrap( ~ Class)+
guides(fill = FALSE)+
theme(
strip.text = element_text(size=13,face="plain",color="black"),
text=element_text(size=12,face="plain",color="black"),
axis.title=element_text(size=14,face="plain",color="black"),
axis.text = element_text(size=11,face="plain",color="black"),
legend.position=c(0.935,0.13),
legend.background = element_rect(fill=alpha("white",0))
)
Alz$male<-as.character(Alz$male)
Alz$male[Alz$male=="0"] <- "Female"
Alz$male[Alz$male=="1"] <- "Male"
colnames(Alz)[colnames(Alz)=="male"]<-"Gender"
ggplot(Alz,aes(x=tau,y=SOD,fill=Class,size=age))+
geom_point(shape=21,colour="black",alpha=0.7)+
facet_grid(Gender~Class)+
guides(fill=F)+
theme_bw()
theme(
strip.text =element_text(size=13,face="plain",color="black"),
text=element_text(size=12,face="plain",color="black"),
axis.title=element_text(size=14,face="plain",color="black"),
axis.text = element_text(size=11,face="plain",color="black"),
legend.position=c(0.935,0.11),
legend.background = element_rect(fill=alpha("white",0)),
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。