How to change facet labels?

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

    Here's another solution that's in the spirit of the one given by @naught101, but simpler and also does not throw a warning on the latest version of ggplot2.

    Basically, you first create a named character vector

    hospital_names <- c(
                        `Hospital#1` = "Some Hospital",
                        `Hospital#2` = "Another Hospital",
                        `Hospital#3` = "Hospital Number 3",
                        `Hospital#4` = "The Other Hospital"
                        )
    

    And then you use it as a labeller, just by modifying the last line of the code given by @naught101 to

    ... + facet_grid(hospital ~ ., labeller = as_labeller(hospital_names))
    

    Hope this helps.

提交回复
热议问题