4

How can I use an ampersand in a facet strip label? I have tried as is, and using unicode with the same result.

MWE

library(ggplot2)

mtcars$am2 <- factor(mtcars$am, labels=c("N[one]==1 \U0026 N[one]==1", 
                                         "N[two]==2 & N[two]==2"))

ggplot(mtcars, aes(mpg, wt)) + 
    facet_grid(. ~ am2, labeller = label_parsed) 

enter image description here

I am using Windows 7 , R3.4.4. Thanks

user2957945
  • 2,353
  • 2
  • 21
  • 40

1 Answers1

2

The solution is to quote the & and use ~ instead of white spaces as is usual in expressions.

"N[two]==2~'&'~N[two]==2"

I'm not entirely sure what is going on here, except, as r2evans suggests in the comments, that the unquoted & is being interpreted as an infix operator.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51