2

I'm having an issue with certain letters and numbers being cutoff/clipped when saved to png. It does not happen if I view the plots within RStudio. It happens with other fonts too besides Palatino, e.g. Book Antiqua.

In the image below you can see that the 'e' is cut off when written vertically but not horizontally. Happens also to some of the tick labels. I have tried different image height/width combinations and it doesn't seem to change it. I checked if it is because the 'e's are at the end of words by putting them in the middle of words also, but seems to be a property of the character regardless of placement. I'm thinking it has something to do with par("cra") or one of those read-only parameters but haven't had success in finding a fix.

I know that I could likely avoid this by using ggplot2 but it is an old code relic and quite complicated to convert out of base plotting. Any suggestions for base plotting?

Windows 10, R 4.0.3, RStudio 1.3.1093

Thanks!

Reprex:

png("650_800.png", type="cairo-png", width=650, height=800, family="Palatino Linotype")
plot(x=1,y=1)
mtext("Absoelute  moistuere ", side=1, cex=1.2)
mtext("Absoelute  moistuere ", side=2, cex=1.2)
mtext("Absoelute  moistuere ", side=3, cex=1.2)
mtext("Absoelute  moistuere ", side=4, cex=1.2)
dev.off()

sample image

TBake
  • 23
  • 4
  • 1
    I'm not able to reproduce this problem on my system (2018 Macbook Pro, R 4.0.2, RStudio 1.3.1054). – eipi10 Dec 30 '20 at 03:20
  • Thanks for trying to help. I'm on Windows 10, R 4.0.3, RStudio 1.3.1093. Must be a Windows thing - no big surprise there... – TBake Dec 30 '20 at 03:24
  • I had no problem on Windows 10, R 4.0.3 and RStudio 1.4.1100 using either `extrafont` or `showtext` packages. https://i.imgur.com/ayGUWKC.png. This is how I added "Palatino Limnotype" to R https://stackoverflow.com/a/51906008/786542 – Tung Dec 30 '20 at 03:51
  • I can reproduce on Windows 10, when using "Palatino Linotype" (if I type "Palatino Limnotype" I don't see the problem but it is a different font). Couldn't solve with `extrafont`, didn't try `showtext`. – Alexlok Dec 30 '20 at 06:23
  • Using `extrafont` or `showtext` I can use Palatino Linotype in the RStudio integrated device, but that doesn't change the output in a `png()` device. – Alexlok Dec 30 '20 at 07:36

1 Answers1

1

I think the problem comes from Cairo, it disappeared when using type="windows":

windowsFonts(Palatino = windowsFont("Palatino Linotype"))

png("650_800.png", type="windows", width=650, height=800, family="Palatino")
plot(x=1,y=1)
mtext("Absoelute  moistuere ", side=1, cex=1.2)
mtext("Absoelute  moistuere ", side=2, cex=1.2)
mtext("Absoelute  moistuere ", side=3, cex=1.2)
mtext("Absoelute  moistuere ", side=4, cex=1.2)
dev.off()

empty plot with text in corners

Alexlok
  • 2,999
  • 15
  • 20