4

I would like to use exponents and variables in the title of my plot.

I tried to use "expression()", but when it is inside a "paste()" method, it prints the literal text, i.e. Volume: paste("Volume(",m^{3},")"). When I use the variable names inside "expression()" the exponent works, but it prints the variable name, i.e. "location" instead of "California".

ggtitle(expression(paste(location,
                          "\nMax Volume Cut-off:", paste(max_volume_criteria, "(", m^{3}, ")"),
                          "\nVolume Percent Decrease:", criteria, sep=" ")))

I am not sure how to get the exponents and the variable names to work at the same time.

b.devog
  • 83
  • 7
  • 3
    Using `bquote` I can get close: `g + ggtitle(bquote(.(location) ~ "\nMax Volume Cut-off:" ~ .(max_volume_criteria) ~ "(" * m^{3} * ")" ~ "\nVolume Percent Decrease:" ~ .(criteria)))`, but the new lines aren't working. [This answer](https://stackoverflow.com/q/15663535/903061) suggests using `atop()` for multiple lines, but `atop(atop(..., ...), atop(..., phantom())` seems messy... – Gregor Thomas Aug 05 '19 at 16:57
  • Thank you. I was able to figure it out! – b.devog Aug 05 '19 at 17:45

1 Answers1

3

using a combination of atop and bquote ended up working:

g + ggtitle(bquote(atop(.(location) ~ "\nMax Volume Cut-off:" ~ .(max_tv_criteria) ~ "(" * m^{3} * ")","Volume Percent Decrease:" ~ .(per_decr_criteria) ~ "%")))
b.devog
  • 83
  • 7