How to change facet labels?

后端 未结 20 1678
既然无缘
既然无缘 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

    Here's how I did it with facet_grid(yfacet~xfacet) using ggplot2, version 2.2.1:

    facet_grid(
        yfacet~xfacet,
        labeller = labeller(
            yfacet = c(`0` = "an y label", `1` = "another y label"),
            xfacet = c(`10` = "an x label", `20` = "another x label")
        )
    )
    

    Note that this does not contain a call to as_labeller() -- something that I struggled with for a while.

    This approach is inspired by the last example on the help page Coerce to labeller function.

提交回复
热议问题