[英]How can you plot `geom_point()` with `facet_wrap()` using per-group row number as x?
有没有办法 plot geom_point()
以便它在一个方面隐式使用行号作为x
? 就像plot(y)
一样,但也适用于多个方面。
以下失败并出现Error: geom_point requires the following missing aesthetics: x
:
df = data.frame(y = rnorm(60), group = rep(c("A", "B", "C"), 20))
ggplot(df, aes(y = y)) +
geom_point() +
facet_wrap(~group)
当然,您可以使用类似以下的方法来完成它,但它非常麻烦。
df = df %>%
group_by(group) %>%
mutate(row = row_number())
ggplot(df, aes(x = row, y = y)) +
geom_point() +
facet_wrap(~group)
你可以试试这个:
ggplot(df, aes(x=seq(y),y = y))+geom_point() + facet_wrap(~group)
这样,您可以避免创建您提到的索引变量!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.