0

It seems that label_parsed function does not work to show an expression for labels of figures in facet_grid (see the figure bellow).

enter image description here

data file is here

I expected that CO2 will show with subscript for 2. It did not and returned an error when I called the figure.

Error in parse(text = as.character(values)) : :1:10: unexpected numeric constant 1: Scenario 2 ^

However, when I removed one of variable 'impact' or 'ID' from the facet_grid() i.e. facet_grid(impact~., scales = "free", space = "fixed", labeller = label_parsed), then CO2 showed the subscript correctly.

What was wrong in my code? could anyone help me please? Thanks a lot in advance.

dat$impact <- factor(dat$impact, 
                     labels = c('GHG(kg CO[2]-e)', 'Fossil fuel (MJ LHV)', 
                                'Water stress (eq L)'))
f <- ggplot(dat, aes(impact, value), fill = stage) +
  facet_grid(impact~ID, scales = "free", space = "fixed", 
             labeller = label_parsed) +
  scale_colour_brewer("clarity")+
  theme(
    axis.title.x = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks.x = element_blank())

f   
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
QVN
  • 19
  • 3
  • Your biggest issue is that your labels aren't valid `expression`s. The text needs to follow the rules laid out in `?plotmath`, so first replace all spaces with `~` (or nest double quotation marks inside your single quotation marks, but that gets messy and hard to read.) – Brian Feb 15 '19 at 20:24
  • Thanks Lin for your comment. I did try that but it does not work. – QVN Feb 17 '19 at 23:21

0 Answers0