ggrepel与geom_smooth一起
ggplot(gapminder::gapminder,aes(x=year,y=lifeExp,label=continent,color=continent))+
geom_line(size=.1,alpha=.2)+
guides(color="none")+
theme_minimal()+
geom_smooth(aes(color=continent),se=F,method="loess")+
ggrepel::geom_label_repel(direction = "y",stat="smooth",nudge_x = 5)
我只想为每个大陆的每个平滑骨料提供一个标签。
我尝试调整参数,但没有帮助。如果我跳过stat =“ smooth”
从GEOM_LABEL_REPEL
中的术语,它将变成所有干草,并试图标记所有单个行 - 而不是平滑的线条。有什么想法吗?
ggplot(gapminder::gapminder,aes(x=year,y=lifeExp,label=continent,color=continent))+
geom_line(size=.1,alpha=.2)+
guides(color="none")+
theme_minimal()+
geom_smooth(aes(color=continent),se=F,method="loess")+
ggrepel::geom_label_repel(direction = "y",stat="smooth",nudge_x = 5)
I only want one label for each smoothed aggregate for each continent.
I´ve tried tweaking the parameters, but to no help. If I skip the stat="smooth"
term from geom_label_repel
It goes all haywire and tries to label all the individual lines - not the smoothed lines. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做到这一点的一种方法是在摘要标签数据框中获取每个大陆的最后一个(或第一个等)拟合的值,然后在
ggrepel
中使用该值:在2022-07-03创建的 reprex软件包(v2.0.1)
One way you could do this is to get the last (or first etc. as desired) fitted value for each continent in a summary label data frame, then use that in
ggrepel
:Created on 2022-07-03 by the reprex package (v2.0.1)