How to change facet labels?

后端 未结 20 1885
既然无缘
既然无缘 2020-11-22 14:50

I have used the following ggplot command:

ggplot(survey, aes(x = age)) + stat_bin(aes(n = nrow(h3), y = ..count.. / n), binwidth = 10)
  + scale         


        
20条回答
  •  眼角桃花
    2020-11-22 15:29

    Both facet_wrap and facet_grid also accept input from ifelse as an argument. So if the variable used for faceting is logical, the solution is very simple:

    facet_wrap(~ifelse(variable, "Label if true", "Label if false"))
    

    If the variable has more categories, the ifelse statement needs to be nested.

    As a side effect, this also allows the creation of the groups to be faceted within the ggplot call.

提交回复
热议问题