将stat_smooth添加到ggplot2中的仅1个面 [英] Adding stat_smooth in to only 1 facet in ggplot2

查看:406
本文介绍了将stat_smooth添加到ggplot2中的仅1个面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据,在一个因素水平上存在显着的相关性。在另一个层面上,没有一个。绘制这些并排很简单。使用stat_smooth向两者添加一条直线也很简单。但是,我不希望将行或其填充显示在两个方面之一中。有没有简单的方法来做到这一点?也许为某一行的填充和颜色指定一个空白颜色?

I have some data for which, at one level of a factor, there is a significant correlation. At the other level, there is none. Plotting these side-by-side is simple. Adding a line to both of them with stat_smooth, also straightforward. However, I do not want the line or its fill displayed in one of the two facets. Is there a simple way to do this? Perhaps specifying a blank color for the fill and colour of one of the lines somehow?

推荐答案

不要考虑挑选方面,请考虑将数据的子集提供给stat_smooth:

Don't think about picking a facet, think supplying a subset of your data to stat_smooth:

ggplot(df, aes(x, y)) +
  geom_point() + 
  geom_smooth(data = subset(df, z =="a")) + 
  facet_wrap(~ z)

这篇关于将stat_smooth添加到ggplot2中的仅1个面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆