1

Example graph:

data.frame(x = c(1,2,3,5,2,3,4,6), y = c(2,3,4,1,4,7,4,1)) %>% ggplot() + geom_point(aes(x = x, y = y)) + annotate('text', x = 3, y = 3, label = 'Heres a plot annotation', size = 5)

...here is the output of the graph from the above code, saved when the graph's width is 500px

enter image description here

...and here's the same graph at 250 pixel width

enter image description here

I'm interesting in finding a way for the annotation text to scale with the width of the ggplot(), that way the text doesn't overflow outside of the graph when the width is smaller (or look too small when the graph becomes larger). In the code above, size = 5 clearly sets a fixed-pixel size font that doesn't scale with the width of the graph. Is there anyway to change this, so the font-size does scale with width?

Canovice
  • 9,012
  • 22
  • 93
  • 211
  • 2
    Seems related: [Adjust font size to size of plot device](https://stackoverflow.com/questions/52304141/adjust-font-size-to-size-of-plot-device) – Henrik Mar 23 '21 at 23:55
  • 1
    Yes it is related. the suggested solution uses ggsave() however I would prefer for the font to scale for any ggplot output (e.g. in the RStudio Viewer), not just for a file saved with ggsave() – Canovice Mar 24 '21 at 00:01

0 Answers0