1

Just started R a couple weeks ago. Getting familiar with ggplot. I successfully made the graph I wanted to including all legends, axes titles, etc. I'm able to export/save this image fine. However, the assignment also required me to change the font used for the title, axes, legend text, etc. on the graph. To import the font I wanted to use, I used showtext as I saw this recommended when I Googled. When I use this, it does change the font to what I want. However, although I can see the entire graphs and its two legends fine in the Plot viewer, when I go to export it, the legend text is now cut off on the right. This appears to be the case as soon as I load the showtext package and use showtext_auto(), even if I just try to then recreate the graph using R's default font, not even with the new font. I've spent tons of time playing around and can't seem to resolve this. Please help. Also would be preferable if there is a more permanent way to get fonts into R rather than me having to load showtext and whatever font I want each and every time. Thank you very much.

3
  • Maybe changing the device option as in e.g. options("device" = "windows") helps. See probably related discussion here: stackoverflow.com/a/53233986/18309711
    – user18309711
    Commented Apr 22, 2022 at 22:01
  • This worked! It also changed how plots are viewed. They no longer show up in Plot viewer in R studio but, rather, in their own window. I'm able to resize and save them fine with no loss of legend. Rather than just fixing a problem, however, I'm trying to understand things. Can you give me a brief explanation of what I did exactly? I tried viewing Help for the options function but still didn't quite get it. Presumably I was telling R that my device is windows... What did it think I was using??
    – Jeff
    Commented Apr 23, 2022 at 14:21
  • Jeff, yes, you were telling R to use the device available (if so) as "windows". Apart from that I know too little about the technical details to tell why this worked and the other didn't. However I encountered some showtext difficulties myself the other week and remembered there was a couple of relevant threads on stackoverflow. So my only skill was retrieving a promising thread from memory ;-)
    – user18309711
    Commented Apr 23, 2022 at 17:03

0

Browse other questions tagged or ask your own question.