我在R
中有一个条形图的代码library(ggplot2)
ggplot(Drugs, aes(factor(Drug), Avbpm, fill = Rate)) +
geom_bar(stat="identity", position = "dodge") +
scale_fill_brewer(palette = "Set1") +
ylab("Beats Per Minute") + xlab("Drug") +
theme(legend.title = element_blank()) +
scale_y_continuous(breaks = seq(0, 350, 25), limits = c(0, 330))
这是我的数据
Drugs <- read.table(
header=TRUE, text='Rate Drug Bpm1 Bpm2 Bpm3
1 "Basal Heart Rate" Nicotine 188 154 158
2 "Drug Induced Heart Rate" Nicotine 274 250 246
3 "Basal Heart Rate" Acetylcholine 200 246 216
4 "Drug Induced Heart Rate" Acetylcholine 96 218 208
5 "Basal Heart Rate" Atropine 220 120 440
6 "Drug Induced Heart Rate" Atropine 280 156 540
7 "Basal Heart Rate" Lidocaine 200 360 320
8 "Drug Induced Heart Rate" Lidocaine 168 240 236')
library(dplyr)
Drugs <- Drugs %>%
mutate(Avbpm = select(., starts_with("B")) %>%
rowMeans(na.rm = TRUE))
这是总共8个柱,我想为每个给定的标准误差平均值添加误差条,例如,尼古丁的基础HR会有误差条10.72898 但是我不知道该怎么做 - 谢谢!