r - 如何在 R 中的分组条形图上创建误差线?
问题描述
我正在查看一篇论文的一些数据,我需要创建一个图表来显示 2 个不同时期(之前和期间)焦虑/抑郁的平均得分差异。我也被指示在图表中插入标准误差线。
当我尝试不带误差线的图表时,我使用 ggplot2 并使用以下代码行获取此条形图:
library(ggplot2)
mh1 <- read.table(
header=TRUE, text='Category mean Period std
1 Depression 0.720 Pre 1.03
2 Depression 0.779 During 0.78
3 Anxiety 0.996 Pre 1.27
4 Anxiety 0.977 During 1.14')
mh1$s <- as.character()
ggplot(mh1, aes(Category, mean, fill = Period)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_brewer(palette = "Set1") +
xlab("") +
ylab("Mean Score") +
ylim(0, 3)
对于误差线,我使用“+”运算符将以下函数附加到上面的函数
geom_errorbar(Category, ymin = mean - std, ymax = mean + std)
但我收到以下错误:
图层错误(数据 = 数据,映射 = 映射,stat = stat,geom = GeomErrorbar,:找不到对象“std”
我对自己做错了什么有点困惑,希望得到一些帮助!
解决方案
推荐阅读
- python - 返回树中的值列表
- python - 比较列表中的元素时出现索引超出范围错误
- javascript - 获取有关数据响应的 TCP 套接字特定数据
- css - 如果我删除 rgba 背景图像出现但如果我写它背景图像消失了,这有什么问题
- python - Python:__init__ 期间 map_async 中的多个参数
- c - 检查数字是否存在于同一行或列矩阵中
- excel - Excel VBA 更新后自动打印范围不起作用
- vba - 生成数据透视图时应用“PivotField.Autosort”
- mysql - 字符编码错误的数据库
- node.js - 得到错误 builder.knex(...).queryBuilder is not a function