ggplot2: facet_wrap strip color based on variable in data set

前端 未结 4 1841
余生分开走
余生分开走 2020-11-28 03:05

Is there a way to fill the strips of facets created with facet_wrap based on a variable supplied with the data frame?

Example data:

MYdata <- data.f

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 03:33

    It's not directly for differently coloring your facets but here you have another (very quick and simpler) solution, based on facet by two variables (size ~ fruit) instead one (~ fruit):

    ggplot(data = MYdata, aes(x = farm, y = weight)) + 
      geom_jitter(position = position_jitter(width = 0.3), 
          aes(color = factor(farm)), size = 2.5, alpha = 1) + 
      facet_wrap(size ~ fruit)
    

提交回复
热议问题