r - non-numeric argument to binary in geom_errorbar -
i'm trying add error bars histograms (only in bars), i'm having problems , couldn't fix this. sample of dataset:
dput(subdat) structure(list(mod = c("mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol", "mme_rcp85", "mme_picontrol"), id = c(4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l, 4l, 5l), variable = structure(c(1l, 1l, 2l, 2l, 3l, 3l, 4l, 4l, 5l, 5l, 6l, 6l, 7l, 7l, 8l, 8l, 9l, 9l, 10l, 10l, 11l, 11l), .label = c("a", "c", "e", "n", "ne", "nw", "s", "se", "sw", "u", "w"), class = "factor"), value = c(23.3739104936128, 20.1308610498121, 18.8255024990622, 19.0964172156593, 5.77035863185792, 5.55522907864065, 7.7881775809746, 6.79307018295126, 4.32731156887715, 3.81988029851766, 7.39932393157495, 6.53369517479574, 7.22600735346051, 7.25113200310887, 3.09683685988686, 3.20062134399185, 5.97626752214253, 5.53675529950584, 5.86005136849718, 4.81357821706405, 10.3562524093597, 9.26876021032058), std = list( 0, 1.1044752690746, 0, 0.985464166294808, 0, 1.28014680316859, 0, 1.26851693389212, 0, 1.31353120434552, 0, 1.04172687591445, 0, 2.37424970962826, 0, 1.27746257356022, 0, 2.46069388335777, 0, 1.31748174778294, 0, 1.64599561125564)), .names = c("mod", "id", "variable", "value", "std"), row.names = c(4l, 5l, 9l, 10l, 14l, 15l, 19l, 20l, 24l, 25l, 29l, 30l, 34l, 35l, 39l, 40l, 44l, 45l, 49l, 50l, 54l, 55l), class = "data.frame")
i doing plot as:
p <- ggplot(subdat,aes(variable,value,fill=mod)) p +geom_bar(stat="identity",position='dodge') p + geom_errorbar(aes(ymin=value-std, ymax=value+std), width=.2, position=position_dodge(.9))
i'm getting error:
error in value - std : non-numeric argument binary operator
i don't know how solve this.
you need change class of std
:
subdat$sd = as.numeric(subdat$std) p <- ggplot(subdat,aes(variable,value,fill=mod)) p <- p + geom_bar(stat="identity",position='dodge') p + geom_errorbar(aes(ymin = value - sd, ymax = value + sd), width = 0.2, position = position_dodge(0.9))
Comments
Post a Comment