我想在ggplot2中用5个横断面绘制5种物种的多重误差棒(平均值和标准偏差)。我试过但没有找到合适的策略。 价值,横断面和物种的示例代码包括以下内容:
value<-as.integer(runif(1000, min = 0, max = 5)) ## values of 1000 observations)
transect <- sample(1:5, 1000, replace=T) ## transect ID
x<-c("SpeciesA","SpeciesB","SpeciesC","SpeciesD","SpeciesE")
species<-rep(x, 200)
data<-data.frame(cbind(value,transect,species)) # species ID
答案 0 :(得分:1)
这是一个例子,他们都在同一个地块上。在geom
position
?stat_summary
和value <- as.integer(runif(1000, min = 0, max = 5)) ## values of 1000 observations)
transect <- sample(1:5, 1000, replace = TRUE) ## transect ID
x <- c("SpeciesA", "SpeciesB", "SpeciesC", "SpeciesD", "SpeciesE")
species <- rep(x, 200)
data <- data.frame(cbind(value, transect, species)) # species ID
library(ggplot2)
ggplot(data, aes(species, value, colour = transect, group = transect)) +
stat_summary(fun.data = mean_se, geom = 'errorbar', position = 'dodge')
中可以使用的好东西
ref_com