r-如何用"facet_wrap()"绘制"geom_point()",使用每组



有没有一种方法可以绘制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)

这样就可以避免创建您提到的索引变量!!!

最新更新