Superscript in R

Use superscripts in R axis labels

It works the same way for axes: parse(text='70^o*N') will raise the o as a superscript (the *N is to make sure the N doesn't get raised too).

labelsX=parse(text=paste(abs(seq(-100, -50, 10)), "^o ", "*W", sep=""))
labelsY=parse(text=paste(seq(50,100,10), "^o ", "*N", sep=""))
plot(-100:-50, 50:100, type="n", xlab="", ylab="", axes=FALSE)
axis(1, seq(-100, -50, 10), labels=labelsX)
axis(2, seq(50, 100, 10), labels=labelsY)
box()

How to subscript/superscript and italicize x-axis labels?

You can add subscripts/superscripts using expression(). Subscripts use [] and superscripts ^.

So: "KA(2,3)2": expression("KA"["2,3"]^2)

Since there is a comma in the (2,3) you need to put it in quotes (or you can add the comma separately: [2*","*3]

Superscript in axis labels in ggplot2 for ions

Try to put the superscript as a literal, between quotes.

g <- ggplot(iris, aes(Species, Sepal.Length)) + geom_boxplot()
g + xlab(bquote('Superscript as a literal' ~~ Ca^'2+'))

ded an image.

How to type subscript/superscript in the category labels in bar plot?

This could be achieved by passing scales::parse_format to the labels argument of the scale. Using ?plotmath notation you have to recode your categories as e.g. K[b] to get a subscript "b":

df <- data.frame(
x = paste0("K[", letters[1:3], "]"),
y = 1:3
)

library(ggplot2)

ggplot(df, aes(x, y)) +
geom_col() +
scale_x_discrete(labels = scales::parse_format())

Sample Image

R language vertically aligned subscripts and superscript in axis of simple plot (not ggplot)?

vec <- seq(-10,10,2)
plot(dta, xlim = c(-10,10), ylim = c(-10,10), axes = F)
axis(1, at=vec, labels=as.expression(mapply(function(num,sub) bquote(.(num)[italic(.(sub))]^degree), abs(vec), ifelse(vec > 0, "E", ifelse(vec < 0, "W", "")))))
axis(2, at=vec, labels=as.expression(mapply(function(num,sub) bquote(.(num)[italic(.(sub))]^degree), abs(vec), ifelse(vec > 0, "N", ifelse(vec < 0, "S", "")))), las=2)

Sample Image



Related Topics



Leave a reply



Submit