如何使用每组行号作为 x 来绘制 `geom_point()` 和 `facet_wrap()`?
How can you plot `geom_point()` with `facet_wrap()` using per-group row number as x?
有没有办法绘制 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)
这样你就可以避免创建你提到的索引变量!!!
有没有办法绘制 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)
这样你就可以避免创建你提到的索引变量!!!