如何使用每组行号作为x来绘制带有“ 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)
iCMS 回答:如何使用每组行号作为x来绘制带有“ facet_wrap()”的“ geom_point()”?

您可以尝试以下方法:

ggplot(df,aes(x=seq(y),y = y))+geom_point() + facet_wrap(~group)

通过这种方式,您可以避免创建您提到的索引变量!!!

本文链接:https://www.f2er.com/1765303.html

大家都在问