gpt4 book ai didi

r - 将闪避与 geom_point 和误差条一起使用以水平显示模型中的系数

转载 作者:行者123 更新时间:2023-12-02 07:58:54 25 4
gpt4 key购买 nike

假设我有以下数据集

                                 term  estimate std.error statistic      p.value   conf.low conf.high  df                outcome model
outgroup_pairing1 9.173850 2.336151 3.926908 0.0001574491 4.539555 13.808145 101 outgroup_feelings_diff 1
outgroup_pairing1 11.663866 3.330378 3.502265 0.0006886152 5.057292 18.270440 101 outgroup_feelings_diff 2
politicsRepublican:outgroup_pairing1 -5.002525 4.645316 -1.076897 0.2840919026 -14.217582 4.212531 101 outgroup_feelings_diff 2
outgroup_pairing1 10.657113 3.575874 2.980282 0.0036079930 3.563540 17.750686 101 outgroup_feelings_diff 3
politicsRepublican:outgroup_pairing1 -4.928449 4.647266 -1.060505 0.2914443020 -14.147374 4.290476 101 outgroup_feelings_diff 3
outgroup_pairing1 10.512772 4.162351 2.525681 0.0131016794 2.255788 18.769757 101 outgroup_feelings_diff 4
politicsRepublican:outgroup_pairing1 -5.359123 4.978743 -1.076401 0.2843123953 -15.235609 4.517363 101 outgroup_feelings_diff 4

我希望能够输出主效应和交互系数及其伴随的误差条,按型号分组。这是我最好的尝试:

ggplot(aes(x = estimate, y = model, color = term, group= term)) + 
geom_vline(xintercept = 0, linetype = 2) +
geom_point(position="dodge") +
geom_errorbarh(aes(xmin = conf.low, xmax = conf.high, height = 0.1),position="dodge") +
ggtitle("Change in Outgroup Warmth") +
geom_text(aes(label = paste("β = ", round(estimate, 2), "; p = ", round(p.value, 5)), vjust = -.5)) +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
ylab("Model") +
xlab("Estimate")

但这会产生以下结果。

enter image description here

我希望系数水平“闪避”,这样它们就不会像那样重叠。我还想删除图例中的“a”。

最佳答案

你不能在当前方向,闪避只在 x 方向有效。但是您可以使用 coord_flip 并以相反的方式定义所有内容:

pos <- position_dodge(width = 0.5)
ggplot(df, aes(y = estimate, x = model, color = term, group= term)) +
geom_hline(yintercept = 0, linetype = 2) +
geom_point(position = pos) +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high, width = 0.1), position = pos) +
ggtitle("Change in Outgroup Warmth") +
geom_text(aes(label = paste("β = ", round(estimate, 2), "; p = ", round(p.value, 5)), vjust = -.5),
position = pos, show.legend = FALSE) +
coord_flip() +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
ylab("Model") +
xlab("Estimate")

enter image description here

另请注意 geom_text 中的 show.legend = FALSE,不要在图例(“a”)中显示文本。

关于r - 将闪避与 geom_point 和误差条一起使用以水平显示模型中的系数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59888853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com