How to change facet labels?

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

    The labeller function defintion with variable, value as arguments would not work for me. Also if you want to use expression you need to use lapply and can not simply use arr[val], as the argument to the function is a data.frame.

    This code did work:

    libary(latex2exp)
    library(ggplot2)
    arr <- list('virginica'=TeX("x_1"), "versicolor"=TeX("x_2"), "setosa"=TeX("x_3"))
    mylabel <- function(val) { return(lapply(val, function(x) arr[x])) }
    ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_line() + facet_wrap(~Species, labeller=mylabel)
    

提交回复
热议问题