landau
landau

Reputation: 5841

ggplot2 facet labeller double subscript

I'm plotting variables with double subscripts, and I would like to be able to keep the subscripts from getting mashed together in the facet strip text. Each label should display something like $\beta_{1, 12}$ instead of $\beta_112$. It should be enough to fix the following MWE.

d = data.frame(
  x = rnorm(6),
  y = rnorm(6), 
  z = rep(paste0("beta[", 1:3, "][", 12, "]"), each = 2))
library(ggplot2)
pl = ggplot(d) + 
  geom_point(aes(x, y)) + 
  facet_wrap(~z, labeller = label_parsed)

enter image description here

Upvotes: 2

Views: 1310

Answers (1)

Mike Wise
Mike Wise

Reputation: 22827

How about this?

library(ggplot2)

d = data.frame(
  x = rnorm(6),
  y = rnorm(6), 
  z = rep(paste0("beta[", 1:3, "~~", 12, "]"), each = 2))
pl = ggplot(d) + 
  geom_point(aes(x, y)) + 
  facet_wrap(~z, labeller = label_parsed)
pl

enter image description here

Upvotes: 1

Related Questions