简体   繁体   English

ggplot2:geom_pointrange()facet_grid()与coord_flip()和自由秤

[英]ggplot2: geom_pointrange() facet_grid() with coord_flip() and free scales

I am trying to generate a graph with the estimates and confidence intervals from the same regression for a number of countries. 我试图从许多国家的同一回归中生成一个包含估计值和置信区间的图表。 I ran the regressions using dplyr 's group_by(country) , and then I aggregated all the results into a data frame with broom 's tidy() . 我使用dplyrgroup_by(country)运行了回归,然后我将所有结果聚合到一个带有broom tidy()的数据框中。

When creating the graph from this data frame (called bycountry1 ), I run the following code: 从此数据框(由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")

这是我得到的图表

This is what I want, except that I'd like to have the scales for each box to be different, so that all of them would look more like the religious1 box. 这就是我想要的,除了我想让每个盒子的刻度不同,所以它们看起来更像是religious1盒子。 Since that is the one with most variability, it dominates the scale, and then in most of the other boxes you cannot see the variance. 由于这是具有最大可变性的那个,它在尺度上占主导地位,然后在大多数其他框中你看不到方差。 As the code above shows, I did indicate scales = "free" in facet_grid() and I tried all the variants, also with facet_wrap() , and I cannot get this to work. 正如上面的代码所示,我确实在facet_grid()指示了scales = "free" ,我尝试了所有变体,也使用了facet_wrap() ,我无法使其工作。

Following the suggestion of aosmith, I made it work using geom_errorbarh and removing coord_flip() . 根据aosmith的建议,我使用geom_errorbarh并删除了coord_flip() I also had to set the height of the geom_errorbarh to 0 and add a geom_point for the estimate. 我还必须将geom_errorbarhheight设置为0并为估计添加geom_point Here is the code: 这是代码:

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")

And the resulting image 并由此产生的图像

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 ggplot2 geom_col 与 facet_grid 和 coord_flip 一起使用 - How to Use ggplot2 geom_col with facet_grid and coord_flip ggplot2:以向量指定的顺序显示间隔,并使用geom_pointrange()和coord_flip()将各个组(例如facet_wrap)分开 - ggplot2: Show intervals in order specified by a vector and separate groups (e.g. with facet_wrap) using geom_pointrange() and coord_flip() 在ggplot2中使用facet_grid和coord_flip删除未使用的级别 - Drop unused level using facet_grid and coord_flip in ggplot2 带有coord_flip的ggplot2中errobar的自由缩放和位置 - Free scales and position of errobar in ggplot2 with coord_flip ggplot2,facet_grid,自由秤? - ggplot2, facet_grid, free scales? ggplot2:将geom_dotplot与facet_grid一起使用时,没有自由轴缩放 - ggplot2: No free axis scales when using geom_dotplot with facet_grid ggplot 0.9.3问题与facet_wrap,自由秤和coord_flip-第二次尝试 - ggplot 0.9.3 issue with facet_wrap, free scales and coord_flip - 2nd try 在ggplot2中,coord_flip和自由缩放不能一起使用 - In ggplot2, coord_flip and free scales don't work together 在ggplot2中使用coord_flip()和facet_wrap(scales =“free_y”)似乎给出了意想不到的facet轴刻度标记和刻度标签 - Using coord_flip() with facet_wrap(scales = “free_y”) in ggplot2 seems to give unexpected facet axis tick marks and tick labels ggplot2 coord_flip()与geom_text - ggplot2 coord_flip() with geom_text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM