gpt4 book ai didi

r - ggplot2:geom_pointrange() facet_grid() 与 coord_flip() 和自由比例

转载 作者:行者123 更新时间:2023-12-04 15:56:51 24 4
gpt4 key购买 nike

我正在尝试生成一个图表,其中包含来自多个国家/地区的相同回归的估计值和置信区间。我使用 dplyr 运行回归的 group_by(country) ,然后我用 broom 将所有结果聚合到一个数据框中的 tidy() .

从该数据框(称为 bycountry1 )创建图形时,我运行以下代码:

ggplot(bycountry1, aes(x = country, y = estimate, ymin = estimate - std.error * 2, ymax = estimate + std.error * 2)) + 
geom_hline(yintercept = 0, colour = "black", lty = 2) +
geom_pointrange() +
coord_flip() + facet_grid(. ~ term, scales = "free")

here is the graph I get

这就是我想要的,除了我想让每个盒子的比例不同,这样所有盒子看起来都更像 religious1盒子。由于那是可变性最大的那个,它在尺度上占主导地位,然后在大多数其他框中你看不到方差。如上面的代码所示,我确实指出了 scales = "free"facet_grid()我尝试了所有的变体,还有 facet_wrap() ,我无法让它发挥作用。

最佳答案

按照 aosmith 的建议,我使用 geom_errorbarh 使其工作并删除 coord_flip() .我还必须设置 heightgeom_errorbarh到 0 并添加 geom_point为估计。这是代码:

ggplot(bycountry1, aes(y = country, x = estimate, xmin = estimate - std.error * 2, xmax = estimate + std.error * 2)) + 
geom_vline(xintercept = 0, colour = "black", lty = 2) +
geom_point() +
geom_errorbarh(height = 0) +
facet_grid(. ~ term, scales = "free")

以及由此产生的图像

enter image description here

关于r - ggplot2:geom_pointrange() facet_grid() 与 coord_flip() 和自由比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34803842/

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