![](/img/trans.png)
[英]How to estimate an SUR model in R with factors to be projected out and clustered standard errors?
[英]plot coefficient point estimate with standard errors for factors
假设我有一个数据框
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
绘制的标准误差,但按因子(组 = 1 或组 = 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="")
但它不会像我想要的那样像分组箱线图一样显示它。 相反,它只是相对于组绘制一个与另一个相邻的点,而我想要这样的例子
你只是想让每个rn
的点根据他们的组移动吗? 在这种情况下,您想要的是使用“躲避”位置:
df = data.frame(rn = factor(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 = factor(c(1,0,1,0)))
ggplot(df, aes(x=rn, y=coef)) +
geom_point(aes(color=group), position = position_dodge(.9)) +
geom_hline(yintercept = 0, color='firebrick')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.