0

I want to annotate my boxplot (create in Base R) with some text and latex formula's, I tried with $..formula..$, but didn't work. Does anyone know a solution?

i = c(1:20)
X = c(13, 18, 25, 58, 25, 31, 39, 42, 17, 35, 46, 22, 18, 20, 26, 14, 33, 19, 20, 21)
df = data.frame(i, X)

boxplot(df$X, data=df, main="Belminuten Data",
        xlab=" ", ylab="Aantal Belminuten",
        frame = FALSE,
        ylimit = c(10, 60),
        range=3)
text(x = c(1.3), y = 60, "n = 20") # n should be in italic or in formula style
text(x = c(.7), y = 23.5, "Med = 23.5")
text(x = c(.7), y = 18.5, "Q_1 = 18.5")
Benjamin Telkamp
  • 1,451
  • 2
  • 17
  • 31

1 Answers1

0
library(latex2exp)

i = c(1:20)
X = c(13, 18, 25, 58, 25, 31, 39, 42, 17, 35, 46, 22, 18, 20, 26, 14, 
33, 19, 20, 21)
df = data.frame(i, X)

boxplot(df$X, data=df, main="Belminuten Data",
   xlab=" ", ylab="Aantal Belminuten",
   frame = FALSE,
   ylimit = c(10, 60),
   range=3)
text(x = c(1.3), y = 60, TeX('$n = 20$'))
text(x = c(.7), y = 13.0, TeX('$Min = 13$'))
text(x = c(.7), y = 18.5, TeX('$Q_1 = 18.5$'))
text(x = c(.7), y = 23.5, TeX('$Med = 23.5$'))
text(x = c(.7), y = 34.0, TeX('$Q_3 = 34$'))
text(x = c(.7), y = 58.0, TeX('$Max = 58$'))
Benjamin Telkamp
  • 1,451
  • 2
  • 17
  • 31