使用已成形的数据框的森林图

时间:2019-02-24 04:51:32

标签: r ggplot2 graph ggpubr forestplot

问题

我有一些数据集,这些数据已经按照以下结构进行处理和导出:

set.seed(123)
library(dplyr)
tb <- tibble(group = rep(c("A", "B"), each = 5),
             wkday = rep(c("Mon", "Tue", "Wed", "Thu", "Fri"), times = 2),
             sta = sample(-3:2, size = 10, replace = T),
             mid = sta + 2,
             fin = sta + 5)

问题

我想生成如下图所示的图。我如何使用ggplot,ggpubr或任何其他R包生成这样的图? enter image description here

1 个答案:

答案 0 :(得分:1)

这应该使您入门:

library(ggplot2)
ggplot(tb, aes(x=wkday, y= mid, ymin= sta, ymax=fin, lower = sta, upper = fin, middle = mid, fill= group)) +
  geom_boxplot(stat = "identity") +
  geom_hline(yintercept=0, linetype="dotted")+
  coord_flip()

enter image description here