Can you specify different geoms for different facets in a ggplot?

前端 未结 2 1411
梦谈多话
梦谈多话 2020-12-02 17:57

How do you specify different geoms for different facets in a ggplot?

(Asked on behalf of @pacomet, who wanted to know.)

2条回答
  •  萌比男神i
    2020-12-02 18:22

    here is another approach by subsetting data:

    ggplot(mtcars, aes(mpg, disp)) + facet_wrap(~cyl) + 
      geom_point(data = subset(mtcars, cyl == 4)) +
      geom_line(data = subset(mtcars, cyl == 6)) +
      geom_text(data = subset(mtcars, cyl == 8), aes(label = gear))
    

    enter image description here

提交回复
热议问题