0

我有这个 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 但是我不知道该怎么做——谢谢!

4

0 回答 0