我正在努力适应tidyr
. 有没有更好的方法来准备anscombe
用于绘图的数据集ggplot2
?具体来说,我不喜欢添加数据(obs_num
)。你会怎么做?
library(tidyverse)
library(datasets)
anscombe %>%
mutate(obs_num = 1:n()) %>%
gather(variable, value, -obs_num) %>%
separate(variable, c("variable", "set"), 1) %>%
spread(variable, value) %>%
ggplot(aes(x = x, y = y)) +
geom_point() +
stat_smooth(method = "lm", se = FALSE, fullrange = TRUE) +
facet_wrap(~set)