How to change facet labels?

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

    I have another way to achieve the same goal without changing the underlying data:

    ggplot(transform(survey, survey = factor(survey,
            labels = c("Hosp 1", "Hosp 2", "Hosp 3", "Hosp 4"))), aes(x = age)) +
      stat_bin(aes(n = nrow(h3),y=..count../n), binwidth = 10) +
      scale_y_continuous(formatter = "percent", breaks = c(0, 0.1, 0.2)) +
      facet_grid(hospital ~ .) +
      opts(panel.background = theme_blank())
    

    What I did above is changing the labels of the factor in the original data frame, and that is the only difference compared with your original code.

提交回复
热议问题