1

I've been looking what seems to be everywhere. I would like to know what the default unit size of annotate() is in ggplot2, as I'm not able to set size to a specific unit in annotate().

For example, I tried the following, but it didn't work:

annotate(geom = "text", label = "Am I a bird?",
           x = "ABC", y = 2375/2,
           family = "Arial", size = unit(10, "mm"), colour = "white")

Error in checkNA("fontsize") : 
  mixture of missing and non-missing values for fontsize

Thanks for your help!

Will M
  • 692
  • 9
  • 20
  • 1
    The size of text is measured in mm. Simply using `size = 10` therefore results in a font size of 10mm. If you want want to draw a 10pt text instead, set size = 10 / ggplot2::.pt. See https://ggplot2.tidyverse.org/articles/ggplot2-specs.html#text. – stefan Mar 23 '20 at 21:58
  • 1
    funnily, this is a constant. To convert to your desired pt, factorise your annotate font size by 5/14 – tjebo Mar 23 '20 at 23:59
  • That worked perfectly, @Tjebo ! Thanks a lot. How did you know it was exactly that factor? Is there an online resource somewhere? – Will M Mar 24 '20 at 00:04
  • 1
    I saw it a couple of years ago somewhere. One of those things... The online resource is actually provided by @IanCampbell in their answer - 14/5 is roughly the same. – tjebo Mar 24 '20 at 00:08
  • 1
    here we go - I think this was the thread. https://stackoverflow.com/questions/25061822/ggplot-geom-text-font-size-control – tjebo Mar 24 '20 at 00:11

1 Answers1

4

It says here that the default unit is mm. So if you want to go from points to mm multiply by 72.27 / 25.4.

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57