我想在我的 ggplot 中插入错误栏,但不起作用。我的下面的代码有什么问题:
set.seed(123)
data<-NULL
data$MeanDecreaseAccuracy <- rnorm(60,10)
data$Feature <- ifelse(data$MeanDecreaseAccuracy > 9,
c("red"), c("blue"))
data$MeanDecreaseGini <- rpois(60,7)
data<-as.data.frame(data)
#
res2<-aggregate(as.numeric(MeanDecreaseGini) ~ Feature , data, mean)
colnames(res2)<-c("Feature","MeanDecreaseGini")
st.err <- function(x, na.rm=FALSE) {
if(na.rm==TRUE) x <- na.omit(x)
sd(x)/sqrt(length(x))
}
sd <- aggregate(as.numeric(MeanDecreaseGini) ~ Feature, data, st.err)
colnames(sd)<-c("Feature","MeanDecreaseGini")
ggplot(res2, aes(x = Feature,
y = MeanDecreaseGini)) +
geom_bar(stat='identity') +
coord_flip() +
theme_classic() +
labs(
x = "Feature",
y = "Importance",
title = "Feature Importance") +
geom_errorbar(aes(ymin=MeanDecreaseGini-sd, ymax=MeanDecreaseGini+sd))
#
Error: Columns `ymin`, `ymax` must be 1d atomic vectors or lists
In addition: Warning messages:
1: In Ops.factor(left, right) : ‘-’ not meaningful for factors
2: In Ops.factor(left, right) : ‘+’ not meaningful for factors