Font spacing whern using cairo_pdf device
Asked Answered
T

0

2

I am using {ggtext} and I noticed that there are gaps in the font spacing when I am using smaller font size.

library(tidyverse)
library(ggtext)

ggplot() +
  annotate(
    "richtext",
    x = 0,
    y = 1,
    label = "<span style = 'font-size:6pt;'>123456789</span>",
    family = "Poppins",
    fill = NA,
    label.color = NA
  ) +
  geom_text(
    aes(
      x = 0,
      y = 1.01
    ),
    label = "123456789",
    family = "Poppins",
    size = 6/.pt
  ) +
  scale_y_continuous(expand = expansion(mult = c(1, 1)))

ggsave("~/Desktop/test.pdf", device = cairo_pdf)
#> Saving 7 x 5 in image
ggsave("~/Desktop/test.png", dpi = 600)
#> Saving 7 x 5 in image

Created on 2020-12-07 by the reprex package (v0.3.0.9001)

This is only problematic when using the cairo_pdf device. If we zoom in on the PNG version, the font spacing looks ok. Any ideas?

enter image description here

Created on 2020-12-07 by the reprex package (v0.3.0.9001)

Tenuto answered 7/12, 2020 at 19:21 Comment(3)
To really figure out where this comes from, it would be helpful to try the same without ggtext. Just annotate with normal geom_text(), and set the fontsize via the size parameter. (Don't forget to divide by .pt to be able to set your fontsize in points, size = 12/.pt.)Consolidate
To be clear: size = 12/.pt sets the font size to 12 pt. To get 4 pt, you need to write size = 4/.pt.Consolidate
Thank you, I have modified accordingly.Tenuto

© 2022 - 2024 — McMap. All rights reserved.