Font size and mtext placement are not compatible in Cairo () and Cairo_png () using cairoDevice library in R

I create some pretty complex diagrams in R using the Cairo library for smooth graphics in Windows 7. I use R2.15.1 and cairoDevice version 2.19. I have a problem with font sizes in Cairo_png () than in simple Cairo () based on the screen, and the placements of mtext are different. To give a simple example:

Code for screen version:

> Cairo(4, 4) > par(bg = "blue") > plot.new() > for (x in 1:30) mtext(format(x), line = -x, outer = TRUE, adj = 0, col = "white") 

Result:

enter image description here

Code for the png version:

 > Cairo_png("test.png", 4, 4) > par(bg = "red") > plot.new() > for (x in 1:30) mtext(format(x), line = -x, outer = TRUE, adj = 0, col = "white") > dev.off() 

The result of the png code:

enter image description here

As you can see, the font is larger in the png version, and the placement of mtext is wider. Is this a mistake or am I doing something wrong?

I must add that Cairo_svg () and Cairo_pdf () behave the same as Cairo_png (). All of them are displayed in the same way, but inconsistently with the screen Cairo ().

+4
source share
1 answer

As we see in the cairoDevice documentation , in your mentioned functions there are different default values ​​for the pointsize parameter:

 Cairo(width = 7, height = 7, pointsize = 8, surface = c("screen", "png", "pdf", "ps", "svg"), filename = Cairo_pdf(filename, width = 7, height = 7, pointsize = 10) Cairo_ps(filename, width = 7, height = 7, pointsize = 10) Cairo_svg(filename, width = 7, height = 7, pointsize = 10) Cairo_png(filename, width = 7, height = 7, pointsize = 10) 

Taking the same pointsize

 Cairo_png("test.png", 4, 4, pointsize = 8) par(bg = "red") plot.new() for (x in 1:30) mtext(format(x), line = -x, outer = TRUE, adj = 0, col = "white") dev.off() 

returns this

enter image description here

+2
source

All Articles