2
[edit 3] At this point, it is possible for me to use the commands:

library(Cairo)
CairoPNG("test.png")
pie( 1:10, labels=paste("label number",1:10))
dev.off()

to obtain the same figure quality.

Someone with apparently the same problem: http://r.789695.n4.nabble.com/Two-questions-on-R-and-cairo-Cairo-td2318527.html


I am wondering why do I obtain different results from the same command using Rstudio, Rscript or just the R console from a terminal. The code I am using is quite clear:

png(filename = "test.png")
pie( 1:10, labels=paste("label number",1:10))
dev.off()

Image obtained using Rstudio: Image obtained using Rstudio

Image obtained using Rscript or the R command prompt from a terminal. (cmd: Rscript script.R ) Image obtained using Rscript/R prompt

[edit 1] When checking the files I produce, I actually have different size and properties:

4,5K test.Rscript.png: PNG image data, 480 x 480, 8-bit colormap, non-interlaced
26K test.Rstudio.png: PNG image data, 480 x 480, 8-bit/color RGB, non-interlaced

[edit 2 : Here I need some more help] Answer from the comment from sinQueso: The result of

Rscript -e 'getOption("bitmapType"); capabilities("cairo");'
"Xlib"
cairo 
FALSE

From Rstudio, I got:

getOption("bitmapType"); capabilities("cairo");
"cairo"
cairo 
TRUE

I checked, I just can not load cairo using the following commands:

Error in library(Cairo) : there is no package called ‘Cairo’
Error in library(cairoDevice) : there is no package called ‘cairoDevice’

(libcairo2-dev is installed)

So I tried:

install.packages('Cairo') 

from R console, but even if I load the Cairo, I am apparently still using the Xlib.

sessionInfo: The only difference: tools_3.3.2 is loaded in RStudio

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Gildas
  • 998
  • 10
  • 16
  • how *exactly* are you saving the graph? Are you really running those precise three lines of code on each platform (i.e., not doing something like clicking the "save graphic" button in RStudio)? – Ben Bolker Jun 08 '17 at 12:58
  • I am doing it just by executing the commands one after the other, yes. – Gildas Jun 08 '17 at 13:02
  • Maybe compare the outputs of `options()`. Just an idea – Aurèle Jun 08 '17 at 13:12
  • I also use Mint 18 and I cannot reproduce: R from the terminal gives me the same proportional font as RStudio – Aurèle Jun 08 '17 at 13:17
  • 1
    What is the output of `Rscript -e 'getOption("bitmapType"); capabilities("cairo");'` – fmic_ Jun 08 '17 at 14:27
  • @sinQueso I got that: [1] "Xlib" cairo FALSE Thanks I think this is the good direction. Why is cairo fine in Rstudio but not in Rscript? – Gildas Jun 09 '17 at 07:31
  • Because it is an add-on package you need to load in your session; RStudio already loads it. There are several package offering it: cairo, cairoDevice, ... Pick one. – Dirk Eddelbuettel Jun 09 '17 at 11:45
  • you could try to force to use cairo by calling `png(..., type="cairo")` (presumably after loading the Cairo package). You'd also want to check that `capabilities("cairo")` returns `TRUE` after loading the package. – fmic_ Jun 09 '17 at 14:03
  • @sinQueso : using `png(..., type="cairo")` does not work. After loading `library(Cairo)` I still have `capabilities("cairo") : FALSE `. But your answer gave me an idea: Using `CairoPNG("test.png")` is working, I actually obtain an image with comparable quality (even a bit bigger in size) when compared to the call in Rstudio. – Gildas Jun 12 '17 at 06:36

0 Answers0