2016-07-12 14 views
0

ヒストグラムにエラーバーを追加しようとしていますが(一部のバーのみ)、問題があり、修正できませんでした。これは私のデータセットのサンプルです:geom_errorbarのバイナリに数値以外の引数

 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") 

として、私はプロットをやっている:私はエラーを取得しています

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)) 

Error in value - std : non-numeric argument to binary operator

私はどのように私を知りませんこれを解決することができます。

答えて

2

あなたはstdのクラスを変更する必要があります:

enter image description here

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)) 
+0

グレート、どうもありがとう – user3231352

関連する問題