Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the unit of text height in ggplot2 annotate?

Tags:

r

ggplot2

My goal is to adjust the hight of annotation according to coordinate scale. To do so, could I know the unit of size in annotate function? (Below, I put size = 10 and it seems the size 10 is about 0.0125 or so.)

library(ggplot2)

ggplot() + 
  geom_point(aes(1, 1)) +
  annotate(
    "text", x = 1, y = 1, label = "My label",
    size = 10,
    hjust = 0
  )

Created on 2020-11-10 by the reprex package (v0.3.0)

like image 377
Soon Avatar asked Nov 22 '25 22:11

Soon


1 Answers

The size is in mm I believe. You can specify size in points by dividing by the constant .pt, which converts points into mm. Note that font size in theme elements is specified in points and doesn't require division by .pt.

library(ggplot2)

ggplot() + 
  geom_point(aes(1, 1)) +
  annotate(
    "text", x = 1, y = 1, label = "My label",
    size = 15/.pt,
    hjust = 0
  ) +
  theme(
    axis.title = element_text(size = 15),
    axis.text = element_text(size = 15)
  )

Created on 2020-11-10 by the reprex package (v0.3.0)

like image 90
Claus Wilke Avatar answered Nov 25 '25 12:11

Claus Wilke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!