1
votes

I have a complex axis label I want to add to a graph in R. It includes superscript and subscript, however, one element of superscript keeps attaching itself to the wrong word in the label. The label should read: umol[tracer]^-1, mmol[sponge]^-1, incubation^-1. The superscript -1 which comes after [sponge] keeps attaching itself to the mmol part, but it should be after the subscript [sponge]. Any help?

FYI the reason I use a text grob in my code below is because I have a primary axis title and a secondary axis title. I am very new to R!

grid.arrange(DC, left=textGrob(expression(paste(mu,"mol C or N "["tracer"]," mmol "["sponge"]^-1," incubation "^-1)), x=2.2, rot=90, hjust=0.38, gp=gpar(fontsize=12)))

This is the output I get, but I want to move the ^-1 to behind the word sponge: Graph

UPDATE:

This is the code for my graph, using the data set iris as an example:

BN <- ggplot(iris, aes(x=Petal.Width, y=Sepal.Length)) + geom_line(position=pd, size=1) + geom_point(position=pd, size=3, shape=21, fill="white") + scale_y_continuous(breaks=0:8*1, limits=c(0,8)) + theme_bw() + theme(plot.title = element_text(hjust = 0.5, size = 18),legend.position="none", panel.border = element_rect(color="black", fill=NA, size=1), panel.grid.major = element_blank(),panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), axis.text=element_text(size=14), axis.title=element_text(size=14), axis.title.x=element_text(margin = unit(c(3,0,0,0), "mm")), axis.title.y=element_blank(), legend.title=element_text(size=14), legend.text=element_text(size=14)) + scale_color_manual(values=c("#999999", "black"))

Using new code from Zhiqiang: b <- grid.arrange(BN, left=textGrob(expression(paste(mu,"mol C or N "["tracer"]," mmol "["sponge"^"-1"]," incubation "^-1)), x=0.5, rot=90, hjust=0.38, gp=gpar(fontsize=10)))

With the new code, the -1 is in the correct place but is too small. updated image

1

1 Answers

0
votes

Is this what you wanted? It would be helpful if you could provide the data.

grid.arrange(DC, left=textGrob(expression(paste(mu,"mol C or N "["tracer"]," mmol "["sponge"^"-1"]," incubation "^-1)), x=2.2, rot=90, hjust=0.38, gp=gpar(fontsize=12)))

EDIT: Adding some space in front of -1 can move it after sponge:

grid.arrange(DC, left=textGrob(expression(paste(mu,"mol C or N "["tracer"]," mmol "["sponge"]^"          -1"," incubation "^-1)), x=2.2, rot=90, hjust=0.38, gp=gpar(fontsize=12)))

enter image description here