Home > other >  Axis title with subscript but ignore second square bracket R
Axis title with subscript but ignore second square bracket R

Time:03-03

I am trying to add a subscript to a ggpubr graph, which I found that I can do quite easily using parse and a set of square brackets. However, the problem is that within the axis label, I have a second set of square brackets that should be in regular type. Something like this:

library(ggpubr)
cars$speed <- log10(cars$speed)
ggscatter(cars, y = "speed", x = "dist", ylab = parse(text = "log[10](speed [μm])"))

I want the base of the logarithm (10) in subscript, but not the distance measure

I want the base of the logarithm (10) in subscript, but not the distance measure, [μm], which should keep it's brackets and stay in normal font size.

I have tried using paste(parse(text = "log[10]"), "(speed [μm])"), parse(text = "log[10](speed \\[μm\\]") and expression, but these have not worked for me so far.

CodePudding user response:

Alternatively use expression...


ggscatter(cars, y = "speed", x = "dist", ylab = expression(log[10]*"(speed [µm])"))

Created on 2022-03-03 by the enter image description here

  • Related