1

I have the below plot, but I'd like to express the isotope names in proper delta format. Previously, I've used the following code for this in an axis label:

p + labs(x = expression(paste(paste(delta^2,"H"))))

But that doesn't work in the facet_grid labeller for my figure below:

p + facet_grid(sex ~ iso,
             scale = "free_x",
             labeller = labeller(iso = c("d2H" = expression(paste(paste(delta^2,"H"))), 
                                         "d13C" = expression(paste(paste(delta^13,"C"))),
                                         "d15N" = expression(paste(paste(delta^15,"N")))),
                                 sex = c("F" = "female",
                                         "M" = "male")))

How can I change the names in the facets?

enter image description here

M--
  • 25,431
  • 8
  • 61
  • 93
tnt
  • 1,149
  • 14
  • 24
  • 3
    Duplicate of [Greek symbol within tha facet labels](https://stackoverflow.com/questions/46971945/greek-symbol-within-tha-facet-labels) – M-- Jun 10 '19 at 17:55

1 Answers1

2

One way is to use label_parsed as a labeller. But to do that the labels of the faceting factor need to be changed to what is to be displayed.
I will use the built-in dataset iris as an example.

library(ggplot2)

iris$Species <- factor(iris$Species, 
                       labels = c(bquote(delta^2*H),
                                  bquote(delta^13*C),
                                  bquote(delta^15*N)))

p <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Width)) +
  geom_point()

p + facet_grid(~ Species,
               scale = "free_x",
               labeller = label_parsed
               )

enter image description here

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66