Adding stat_smooth in to only 1 facet in ggplot2

后端 未结 2 1411
名媛妹妹
名媛妹妹 2021-02-07 05:35

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 l

2条回答
  •  后悔当初
    2021-02-07 06:03

    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)
    

提交回复
热议问题