在ggplot2中轻松添加'(全部)'facet到facet_wrap? [英] Easily add an '(all)' facet to facet_wrap in ggplot2?
问题描述
我在 facet_wrap $>中有这样的数据c $ c>文档
:
http://docs.ggplot2.org/current/facet_wrap-29.png
我想填补最后一个方面总体来看,使用所有数据。
有没有一种简单的方法可以用 facet_wrap
添加'total'很容易为 facet_grid
添加保证金,但该选项不存在于 facet_wrap
中。
注意:如果您需要像上图那样的象限,那么使用 facet_grid
不是一个选项,它需要 ncol
或 nrow
从 facet_wrap
。
library(ggplot2)
p < - qplot(displ,hwy,data = transform(mpg, (数据=变换(cyl6,cyl =7),色彩=子集(mpg,cyl == 6)红色)+
geom_point(data = transform(mpg,cyl =all),color =blue)+
facet_wrap(〜cyl)
p>
I have data that looks like this example in the facet_wrap
documentation:
http://docs.ggplot2.org/current/facet_wrap-29.png
I would like to fill the last facet with the overall view, using all data.
Is there an easy way to add a 'total' facet with facet_wrap
? It's easy to add margins to facet_grid
, but that option does not exist in facet_wrap
.
Note: using facet_grid
is not an option if you want a quadrant as in the plot above, which requires the ncol
or nrow
arguments from facet_wrap
.
library(ggplot2)
p <- qplot(displ, hwy, data = transform(mpg, cyl = as.character(cyl)))
cyl6 <- subset(mpg, cyl == 6)
p + geom_point(data = transform(cyl6, cyl = "7"), colour = "red") +
geom_point(data = transform(mpg, cyl = "all"), colour = "blue") +
facet_wrap(~ cyl)
这篇关于在ggplot2中轻松添加'(全部)'facet到facet_wrap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!