使用 ggplot2 在构面中包含未使用的因子水平
有没有办法包含一个用于分面中未使用的因子级别的面板?
我想要这样做的原因是因为我在行中排列了几个单独的图,显示不同的度量,每行在列中具有相同数量的 facet_grid
面板。每个图应按列排列。
但是,当其中一行的数据缺少特定构面级别的数据时,面板的数量将不同,并且列不会对齐。例如,请注意最后一行缺少“数学 II”面板:
示例图 http://dl.dropbox.com/u/14792859/ggplot2%20facet%20levels.png
我能想到的唯一解决方法是为任何缺失的构面级别包含一个虚拟数据点,但我很想听到有一种更简单/更干净的方法。
Is there a way to include a panel for unused levels of a factor used in faceting?
The reason I want to do this is because I'm arranging several separate plots in rows showing different measures, with each row having the same number of facet_grid
panels in columns. Each plot should line up by column.
But when the data for one of the rows is missing data for a particular facet level, the number of panels will be different and the columns do not line up. For example, notice the last row is missing the "Mathematics II" panel:
Example plot http://dl.dropbox.com/u/14792859/ggplot2%20facet%20levels.png
The only work-around I can think of is to include a dummy data-point for any missing facet levels, but I would love to hear that there is an easier/cleaner way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Ben Bolker 提到的,这似乎是由 plyr 中的错误引起的 ggplot2 中的错误。该问题预计将在即将发布的 plyr 1.5 版本中修复。
同时,我通过创建单个图并使用facet_grid来解决这个问题,其中行指定要绘制的不同度量。问题是我无法为两个底部面板指定不同的scale_fill_manual,因此我对中间面板使用了描边颜色——虽然不理想,但目前已经足够好了。
感谢 Ben 解决了这个问题并开始了邮件列表对话。
As Ben Bolker mentioned, this appears to be a bug in ggplot2 caused by a bug in plyr. This is slated to be fixed in the upcoming plyr 1.5 release.
In the meanwhile, I worked around the issue by creating a single plot and using facet_grid, with rows specifying the different measures to be plotted. The problem with this is that I can't specify a different scale_fill_manual for the two bottom panels, so I used stroke color for the middle panel instead -- not ideal but good enough for now.
Thanks Ben for figuring this out and starting the mailing list conversation.