dplyr
在下图中,我显示了一组模型中的 $R^2$ 值,这些模型使用和拟合到数据集的子集broom
。我想按线连接点,或者像传统的点图一样在每个点上画水平线。我怎样才能做到这一点?
代码
library(dplyr)
library(ggplot2)
library(gapminder)
library(broom)
# separate models for continents
models <- gapminder %>%
filter(continent != "Oceania") %>%
group_by(continent) %>%
do(mod = lm(lifeExp ~ year + pop + log(gdpPercap),
data=.)
)
models %>% glance(mod)
gg <-
models %>%
glance(mod) %>%
ggplot(aes(r.squared, reorder(continent, r.squared))) +
geom_point(size=4) +
ylab("Continent")
gg
我尝试添加geom_line()
,但无法理解group
在这种情况下我如何使用美学
gg + geom_line()
geom_path: Each group consists of only one observation. Do you need to adjust
the group aesthetic?
gg + geom_line(aes(group=continent))
或者,我尝试geom_line()
如下,但没有成功:
> gg + geom_hline(yintercept=levels(continent))
Error in levels(continent) : object 'continent' not found