Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如果使用交互绘图,如何在GGplot2中添加错误条_R_Ggplot2 - Fatal编程技术网

R 如果使用交互绘图,如何在GGplot2中添加错误条

R 如果使用交互绘图,如何在GGplot2中添加错误条,r,ggplot2,R,Ggplot2,亲爱的斯塔克沃夫人 我想在交互图中添加错误条。如果没有错误条形码,代码运行良好。 但是如果我添加错误条形码,我将得到以下消息: 德鲁克(信心) 警告信息: 1:在运算因子(z,se)中:“-”对于因子没有意义 2:在运算因子(z,se)中:“+”对因子没有意义 3:删除了包含缺失值的668行(geom_errorbar) 如果我将变量转换为数字,我将得到以下消息 德鲁克(x$Intelligence) z-se中出错:二进制运算符的非数值参数 这是我的代码+dput的输出(head(x,20))

亲爱的斯塔克沃夫人

我想在交互图中添加错误条。如果没有错误条形码,代码运行良好。 但是如果我添加错误条形码,我将得到以下消息:

德鲁克(信心) 警告信息: 1:在运算因子(z,se)中:“-”对于因子没有意义 2:在运算因子(z,se)中:“+”对因子没有意义 3:删除了包含缺失值的668行(geom_errorbar)

如果我将变量转换为数字,我将得到以下消息

德鲁克(x$Intelligence) z-se中出错:二进制运算符的非数值参数

这是我的代码+dput的输出(head(x,20))(在注释中请求)

##准备数据
x=ForkinDatenFlamingo
##紫外线
#小的
姿态=系数(x$Pos)
性别=系数(x$性别)
视图(x)

对比(姿势)如何调用函数?你能发布代码和样本数据吗?请使用您运行的代码和
dput(df)
的输出编辑问题。或者,如果dput(头部(df,20))的输出太大
。(
df
是您的数据集的名称。)如前所述,如果您添加了数据集,其他人将更容易找到解决您问题的方法。关于您的错误:
se
是否属于
因子类型?你是如何计算标准误差的?@RuiBarradas我添加了代码和数据子集。我同意dario的观点:我想从一个因子计算SE。你可以把问题归结为“如何计算分类数据的标准误差”。简短回答:分类数据没有标准差/标准误差。但是你可以计算
##Prepare Data
x = ForkinDatenFlamingo

##UV
#Small
Posture= factor(x$Pos)
Sex= factor(x$Sex)

View(x)

contrasts(Posture) <- -1*contr.sum(2)
contrasts(Sex) <- -1*contr.sum(2)

##Fixed


Intelligence = factor(x$Intelligence)

#######################
Drucker <- 
  function(z) {
    library(ggplot2)  
    # library(FSA)
    name1 <- deparse(substitute(z))
    filename <- sprintf("Plot%s.png", gsub(" ", "_", name1))
    p<-(ggplot() + aes(x = Posture, color = Sex, group = Sex, y = z) +
          stat_summary(fun.y = mean, geom = "point") +
          stat_summary(fun.y = mean, geom = "line") + coord_cartesian(ylim = c(1.5, 3.5)) +
          labs(title = name1, x="Physician's posture") +
          ylab (name1))+ 
      #geom_errorbar(aes(ymin=z-se, ymax=z+se), width=.2) +

      scale_y_discrete(breaks=c("1","2","3","4"),labels=c("4th rank", "3rd rank", "2nd rank", "1st rank")) +
      scale_color_discrete(name = "Sex of physician", labels = c("female physician", "male physician"))
    ggsave(filename,p, width = 5, height = 5)
  }

Drucker(Intelligence)

# first 20 rows
> x <- structure(list(No = c(31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 
41, 42, 43, 44, 45, 46, 47, 48, 49, 50), SetID = c(2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Picid = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), PicName = c("F1A", 
"F1A", "F1A", "F1A", "F1A", "F1A", "F1A", "F1A", "F1A", "F1A", 
"F1A", "F1A", "F1A", "F1A", "F1A", "F1A", "F1A", "F1A", "F1A", 
"F1A"), Sex = c("F", "F", "F", "F", "F", "F", "F", "F", "F", 
"F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F"), Person = c(3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), Pos = c("Open", 
"Open", "Open", "Open", "Open", "Open", "Open", "Open", "Open", 
"Open", "Open", "Open", "Open", "Open", "Open", "Open", "Open", 
"Open", "Open", "Open"), `Single Posture` = c(1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), Leader = c(0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), Confidence = c(2, 
3, 3, 2, 2, 2, 4, 4, 3, 1, 4, 4, 4, 4, 4, 3, 4, 4, 3, 4), Power = c(2, 
3, 1, 3, 3, 2, 2, 2, 2, 1, 2, 3, 3, 4, 2, 4, 3, 4, 4, 4), Intelligence = c(2, 
3, 2, 3, 2, 2, 4, 4, 2, 1, 3, 4, 3, 4, 1, 4, 3, 4, 4, 4), `Commitement Patient` = c(2, 
3, 3, 1, 1, 2, 3, 2, 2, 2, 3, 3, 4, 3, 3, 3, 4, 4, 4, 3), `Ethical behaviour` = c(4, 
3, 3, 3, 2, 2, 4, 3, 2, 1, 4, 4, 4, 4, 2, 3, 4, 4, 1, 4), Teamplayer = c(1, 
3, 2, 1, 2, 2, 2, 3, 3, 1, 3, 3, 2, 2, 3, 3, 2, 4, 3, 3), Communicator = c(2, 
1, 3, 1, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 4, 2, 4, 2, 4), Advocate = c(1, 
3, 3, 1, 1, 2, 4, 3, 3, 2, 4, 2, 2, 2, 4, 3, 4, 4, 1, 4), `care family` = c(2, 
3, 1, 1, 3, 2, 4, 2, 3, 2, 1, 3, 4, 4, 2, 4, 4, 4, 1, 4), EBD = c(2, 
3, 3, 3, 3, 2, 4, 4, 1, 1, 4, 1, 4, 3, 4, 4, 4, 4, 3, 4), `Medical Xpert` = c(0, 
0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1), Ask = c(2, 
1, 3, 1, 2, 3, 3, 2, 1, 1, 3, 2, 3, 3, 1, 2, 2, 4, 3, 4), `Personal preferences` = c(3, 
1, 3, 1, 1, 2, 4, 4, 4, 1, 1, 2, 4, 3, 4, 3, 2, 4, 3, 3), `Pro n Cons` = c(3, 
1, 2, 1, 1, 3, 3, 4, 4, 2, 3, 4, 3, 3, 4, 4, 4, 4, 4, 4), Deriates = c(1, 
4, 2, 1, 2, 2, 4, 1, 1, 2, 3, 1, 1, 3, 2, 2, 2, 1, 3, 1), Serious = c(4, 
4, 2, 1, 4, 1, 4, 1, 2, 1, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4), Solari = c("AB", 
"CD", "BC", "BD", "AB", "DE", "BD", "CE", "BC", "DE", "BC", "AD", 
"CD", "BD", "BD", "BD", "BC", "BC", "AB", "BD"), NSol = c(1, 
2, 1, 3, 1, 2, 3, 3, 1, 2, 1, 3, 2, 3, 3, 3, 1, 1, 1, 3), SolriTranskr = c(1, 
3, 2, 7, 1, 4, 7, 7, 2, 4, 2, 7, 3, 7, 7, 7, 2, 2, 1, 7), VPSex = c(2, 
2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2), Alter = c(25, 
31, 46, 39, 25, 28, 25, 31, 28, 35, 28, 35, 35, 48, 35, 25, 39, 
58, 35, 29), Bildung = c(4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 3, 4, 4, 4, 3, 4, 3), Ethnicity = c(4, 1, 1, 1, 4, 4, 1, 4, 
5, 3, 1, 1, 1, 1, 2, 4, 1, 1, 1, 1), `Doctor Frequency` = c(5, 
2, 6, 1, 5, 3, 5, 4, 2, 6, 0, 1, 1, 4, 1, 10, 3, 2, 0, 0)), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))