压砂地年终重新作图(涉及方差分析、图片合并、标准差与标准误的转化)

#宁夏中卫压砂地蝗虫对不同景观格局的响应
.libPaths()
rm(list=ls())
install.packages(agricolae)
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区蝗虫")

datnames <- names(dat)
anova <- aov(N~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("个体数(N)")+xlab("")+
  
  theme_classic()+

theme(legend.position = "none",axis.line = element_line(linewidth=1),
      
      axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,8))
p1

22222222222222222222222222222222222222222222222222222222222222222222
dat <- read_excel("year end se.xlsx",sheet = "6区蝗虫")

datnames <- names(dat)
anova <- aov(S~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p2 <- ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("物种数(S)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,4))
p2


ggarrange(p1,p2, ncol = 2,nrow = 1)

ggarrange(p1,p2, nrow = 2,ncol= 1)
ggarrange(p1, p2, ncol = 2, nrow = 1, gap = unit(0.05, "mm"))




#宁夏中卫压砂地三种优势蝗虫对不同景观格局的响应
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区优势蝗虫")

datnames <- names(dat)
anova <- aov( DX~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("短星翅蝗个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,4))
p1
222222222222222222222222222222222
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区优势蝗虫")

datnames <- names(dat)
anova <- aov( PS~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("裴氏短鼻蝗个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,3))
p2
333333333333333333333333333333#白纹
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区优势蝗虫")

datnames <- names(dat)
anova <- aov( BW~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("白纹雏蝗个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,4))
p3

ggarrange(p1,p2,p3, ncol = 3,nrow = 1)






#蝗虫天敌多样性
Q <- 1:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区天敌")

datnames <- names(dat)
anova <- aov( N~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,100))
p1


Q <- 2:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区天敌")

datnames <- names(dat)
anova <- aov( S~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("物种数(S)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,15))
p2

Q <- 3:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区天敌")

datnames <- names(dat)
anova <- aov( d~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Margalef丰富度指数(d)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,4))
p3
Q <- 4:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区天敌")

datnames <- names(dat)
anova <- aov( D~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p4 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Simpson集中性概率指数(λ)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,0.5))
p4
Q <-5:6
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区天敌")

datnames <- names(dat)
anova <- aov( H~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p5 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Shannon-Wiener多样性指数(H′)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,3))
p5
Q <-6:6
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区天敌")

datnames <- names(dat)
anova <- aov( J~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p6 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Pielou均匀度指数(E)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,1))
p6

ggarrange(p1,p2,p3,p4,p5,p6, ncol = 3,nrow = 2)


#蝗虫天敌优势种个数

library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区优势天敌数量")

datnames <- names(dat)
anova <- aov( ZJ~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("直角通缘步甲个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,15))
p1
222222222222222222222222222222222
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区优势天敌数量")

datnames <- names(dat)
anova <- aov( GB~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("广布弓背蚁个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,25))
p2
333333333333333333333333333333
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区优势天敌数量")

datnames <- names(dat)
anova <- aov( AJ~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("艾箭蚁个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,50))
p3

ggarrange(p1,p2,p3, ncol = 3,nrow = 1)

#植被多样性
Q <- 1:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区植被多样")

datnames <- names(dat)
anova <- aov( N~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,120))
p1


Q <- 2:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区植被多样")

datnames <- names(dat)
anova <- aov( S~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("物种数(S)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,5))
p2

Q <- 3:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区植被多样")

datnames <- names(dat)
anova <- aov( d~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Margalef丰富度指数(d)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,1))
p3
Q <- 4:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区植被多样")

datnames <- names(dat)
anova <- aov( D~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p4 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Simpson集中性概率指数(λ)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,0.8))
p4
Q <-5:6
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区植被多样")

datnames <- names(dat)
anova <- aov( H~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p5 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Shannon-Wiener多样性指数(H′)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,1.5))
p5
Q <-6:6
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "6区植被多样")

datnames <- names(dat)
anova <- aov( J~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
plotdata2 <- plotdata %>% mutate(se = std / sqrt(5))
View(plotdata2)
p6 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Pielou均匀度指数(E)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,1))
p6

ggarrange(p1,p2,p3,p4,p5,p6, ncol = 3,nrow = 2)





#优化后的蝗虫

library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区蝗虫")

datnames <- names(dat)
anova <- aov(N~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,5))
p1

22222222222222222222222222222222222222222222222222222222222222222222
dat <- read_excel("year end se.xlsx",sheet = "3区蝗虫")

datnames <- names(dat)
anova <- aov(S~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means
 
datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了

View(plotdata2)
p2 <- ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("物种数(S)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,3))
p2


ggarrange(p1,p2, ncol = 2,nrow = 1)





#区优势种,三种优势蝗虫对不同景观格局的响应

library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区优势蝗虫数量")

datnames <- names(dat)
anova <- aov( DX~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("短星翅蝗个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,2))
p1
222222222222222222222222222222222
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区优势蝗虫数量")

datnames <- names(dat)
anova <- aov( PS~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("裴氏短鼻蝗个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,1.5))
p2
333333333333333333333333333333#白纹
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区优势蝗虫数量")

datnames <- names(dat)
anova <- aov( BW~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("白纹雏蝗个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,2))
p3

ggarrange(p1,p2,p3, ncol = 3,nrow = 1)





#天敌多样性


Q <- 1:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区天敌")

datnames <- names(dat)
anova <- aov( N~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,80))
p1


Q <- 2:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区天敌")

datnames <- names(dat)
anova <- aov( S~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("物种数(S)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,15))
p2

Q <- 3:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区天敌")

datnames <- names(dat)
anova <- aov( d~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Margalef丰富度指数(d)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,3))
p3
Q <- 4:6
Q
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区天敌")

datnames <- names(dat)
anova <- aov( D~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p4 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Simpson集中性概率指数(λ)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,0.5))
p4
Q <-5:6
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区天敌")

datnames <- names(dat)
anova <- aov( H~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p5 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Shannon-Wiener多样性指数(H′)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,2))
p5
Q <-6:6
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区天敌")

datnames <- names(dat)
anova <- aov( J~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p6 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("Pielou均匀度指数(E)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,1))
p6

ggarrange(p1,p2,p3,p4,p5,p6, ncol = 3,nrow = 2)

#3区蝗虫天敌优势种个数

library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区优势天敌数量")

datnames <- names(dat)
anova <- aov( ZJ~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p1 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("直角通缘步甲个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,15))
p1
222222222222222222222222222222222
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区优势天敌数量")

datnames <- names(dat)
anova <- aov( GB~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p2 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("广布弓背蚁个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,25))
p2
333333333333333333333333333333
library(agricolae)
library(ggplot2)
library(readxl)
library(dplyr)

dat <- read_excel("year end se.xlsx",sheet = "3区优势天敌数量")

datnames <- names(dat)
anova <- aov( AJ~sample, data = dat)
summary(anova)
result <- duncan.test(anova, 'sample')
datmeans <- result$means

datgroups <- result$groups

print(datgroups)

ind <- match(row.names(datmeans), row.names(datgroups))

datmeans$groups <- datgroups$groups[ind]

names(datmeans)[1] <- datnames[1]

plotdata <- as.data.frame(cbind(row.names(datmeans), datmeans[, 1], datmeans$std, as.character(datmeans$groups)))

names(plotdata) <- c("Treat", "y", "std", "groups")

plotdata$y <- as.numeric(as.character(plotdata$y))

plotdata$std <- as.numeric(as.character(plotdata$std))


View(plotdata)
divisor<- c(sqrt(5), sqrt(10), sqrt(15))

plotdata2 <- plotdata %>% mutate(se = std / divisor)#注意重复变了
View(plotdata2)
p3 <-ggplot(plotdata2,aes(x = Treat,y = y,fill=Treat)) +
  
  geom_text(mapping = aes(y = y + se, label = groups), vjust = -1)+
  
  geom_col(width = 0.6)+
  
  geom_errorbar(aes(ymin = y,ymax = y+se), width = 0.25) +
  
  ylab("艾箭蚁个体数(N)")+xlab("")+
  
  theme_classic()+
  
  theme(legend.position = "none",axis.line = element_line(linewidth=1),
        
        axis.ticks = element_line(colour = "black",size=1,lineend="round"))+
  
  scale_y_continuous(expand=c(0,0),limits = c(0,30))
p3

ggarrange(p1,p2,p3, ncol = 3,nrow = 1)


你可能感兴趣的:(excel,r语言,数据分析)