可以用于一张图里面画好几张图
使用gridextra
最后采用grid.arrange分布
library(gridExtra)
data$IncomeRange <- factor(data$IncomeRange,order=TRUE,levels = c("Not displayed","Not employed","$0","$1-24,999","$25,000-49,999","$50,000-74,999","$75,000-99,999","$100,000+"))
p1 <- ggplot(aes(x=InquiriesLast6Months,fill=newLoanStatus),
data=subset(data,!(is.na(data$InquiriesLast6Months)|is.na(data$newLoanStatus))))+
geom_bar(position = position_fill())+scale_x_continuous(limits = c(-1,11))+ylab("Propotion")
p2 <- ggplot(aes(x=DelinquenciesLast7Years,fill=newLoanStatus),data
=subset(data,!(is.na(data$newLoanStatus))))+
geom_bar(position = position_fill())+scale_x_continuous(limits = c(-1,101))+ylab("Propotion")
p3 <- ggplot(aes(x=DebtToIncomeRatio,fill=newLoanStatus),data
=subset(data,!(is.na(data$newLoanStatus))))+geom_bar(binwidth=0.1,position
=position_fill())+scale_x_continuous(limits = c(0,1))+ylab("Propotion")
p4 <- ggplot(aes(x=IncomeRange,fill=newLoanStatus),data=subset(data,
!(data$IncomeRange=="Notdisplayed"|is.na(data$newLoanStatus))))+geom_bar(position=position_fill())+ylab("Propotion")+theme(axis.text = element_text(size = 4.5))
grid.arrange(p1,p2,p3,p4,ncol = 2) #设置两列