我试图使用二元结果变量(' cr')来绘制因子('情绪' 3级)的主效应ggplot中的r。
#computing mean and sd
data_summary <- function(data, varname, groupnames){
require(plyr)
summary_func <- function(x, col){
c(mean = mean(x[[col]], na.rm=TRUE),
sd = sd(x[[col]], na.rm=TRUE))
}
data_sum<-ddply(data, groupnames, .fun=summary_func,
varname)
data_sum <- rename(data_sum, c("mean" = varname))
return(data_sum)
}
sophie1 <- data_summary(sophie, varname="cr", groupnames ="emotion")
head(sophie1)
base_plot <- ggplot(sophie, aes(x = emotion, y = cr)) +
stat_summary(aes(fill = factor(emotion)), fun.y = mean, geom = "bar", color = "black") +
scale_fill_manual(values = c("#3182bd", "#636363", "#e6550d")) + # colorbrewer2.org
theme(legend.position = "none") +
theme_bw() +
xlab("Emotions") + ylab("Pr (correct response)")+
geom_errorbar(aes(ymin=cr-sd, ymax=cr+sd), width=.2,
position=position_dodge(.9)) +
theme(panel.grid.major = element_blank())
print(base_plot)
我收到此错误消息:
Error in cr - sd : non-numeric argument to binary operator
感谢您的帮助。