OverFlow Police
OverFlow Police

Reputation: 861

ggplot Text in math notation

I would like to add a text to ggplot. I would like to add 10^-3, but R actually computes it, and adds 0.001 to the plot.

How can I tell it to just do $10^(-3)$ to have 10 as a base and "-3" as exponent.

Upvotes: 0

Views: 546

Answers (1)

Indrajeet Patil
Indrajeet Patil

Reputation: 4889

Since you haven't provided any data or any other details about where exactly you want to display this text, I've taken the liberty to display it as a subtitle and also added some other text to show how both super- and sub-script can be handled-

# setup
set.seed(123)
library(ggplot2)

# plot
ggplot(mtcars, aes(as.factor(am), wt)) + geom_point() +
  labs(subtitle = expression(eta[p]^2 == 10^-3))

Created on 2018-12-08 by the reprex package (v0.2.1)

Upvotes: 3

Related Questions