用ggplot2中geom_bar做并行摆放条形图

setwd("C:/Users/chengdehe/Desktop/paper/自动核磁")

library(tidyr)

library(ggplot2)

数据格式


########TW=500

data <- read.table("clipboard",header=T,sep='\t',check.names=F)

plotdata <- gather(data, key = moisture, value = range, 2:8)

p1 <- ggplot(plotdata,aes(x=moisture,y=range,fill=累加次数))+

      geom_bar(position="dodge",stat="identity")+

      xlab("含水率%") + ylab("极差") + labs(fill="累加次数",title="TW=500")+

      theme_classic()

#########TW=1000

data <- read.table("clipboard",header=T,sep='\t',check.names=F)

plotdata <- gather(data, key = moisture, value = range, 2:8)

p2 <- ggplot(plotdata,aes(x=moisture,y=range,fill=累加次数))+

  geom_bar(position="dodge",stat="identity")+

  xlab("含水率%") + ylab("极差") + labs(fill="累加次数",title="TW=1000")+

  theme_classic()

#########TW=1500

data <- read.table("clipboard",header=T,sep='\t',check.names=F)

plotdata <- gather(data, key = moisture, value = range, 2:8)

p3 <- ggplot(plotdata,aes(x=moisture,y=range,fill=累加次数))+

  geom_bar(position="dodge",stat="identity")+

  xlab("含水率%") + ylab("极差") + labs(fill="累加次数",title="TW=1500")+

  theme_classic()

#########TW=2000

data <- read.table("clipboard",header=T,sep='\t',check.names=F)

plotdata <- gather(data, key = moisture, value = range, 2:8)

p4 <- ggplot(plotdata,aes(x=moisture,y=range,fill=累加次数))+

  geom_bar(position="dodge",stat="identity")+

  xlab("含水率%") + ylab("极差") + labs(fill="累加次数",title="TW=2000")+

  theme_classic()

##创建画布

##install.packages("customLayout")

library(customLayout)

mat <- matrix(1:4,ncol=2)

widths <-c(1,1)

heights <-c(1,1)

pl <-lay_new(mat,widths,heights)

#将图片放入画布

lay_grid(list(p1,p2,p3,p4),pl)

结果

你可能感兴趣的:(用ggplot2中geom_bar做并行摆放条形图)