Category Hierarchy

假设我有一个数据帧

rn = c('disease1', 'disease1', 'disease2', 'disease2') 
coef = c(0.1, 0.2, 0.3, 0.4) 
std = c(0.003, 0.003, 0.002, 0.0004) 
group = c(1,0,1,0)
df = data.frame(rn, coef, std)  

我想要做的是得到一个图,在这个图中我可以得到系数和每个给定rn的标准误差图,但要按因子( group=1或group=0)进行绘制。

现在我的代码是

library('ggplot2')
plot_heterogenous <- ggplot(df, aes(x=factor(rn), y=coef)) +
  geom_hline(yintercept = 0, color='firebrick') +
  geom_point(aes(fill=as.factor(group))) +
  geom_errorbar(aes(ymin=wave1_coef-wave1_std, ymax=wave1_coef+wave1_std), width=0, color="steelblue4") + 
  coord_flip() + scale_y_continuous(limits = c(-0.2, 0.2)) +
  theme_bw()+
  theme(panel.grid.major.x = element_blank(), 
        panel.grid.minor.x = element_blank(),
        panel.border = element_blank())+
  labs(y= "Treatment effect (standard deviations)", x="")

但它并不像我想要的那样显示成分组的箱形图。相反,它只是根据组将一个点紧挨着另一个点作图,而我想要像这样的example

?

?

转载请注明出处:http://www.ydsst.com/article/20230312/1975402.html