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+'))
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())
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)
Related Topics
Learning to Write Functions in R
Geom_Smooth with Facet_Grid and Different Fitting Functions
Linear Regression with Constraints on The Coefficients
How to Fix Axis Margin with Ggplot2
Change Plot Panel in Multipanel Plot in R
How to Draw a Boxplot Without Specifying X Axis
How Does The Subset Argument Work in The Lm() Function
R Eps Export and Import into Word 2010
The Fastest Way to Convert Numeric to Character in R
R: Remove Repeating Row Entries in Gridextra Table
Change Font Size for All Inline Equations R Markdown
How to Fuzzy Join Based on Multiple Columns and Conditions
Block Bootstrap from Subject List
How to Convert a Data Frame of Integer64 Values to Be a Matrix