em70
em70

Reputation: 6081

Save R Cairo graphics on windows

I've just found out that I can get antialiased R graphics on Windows via Cairo so I've installed the package right away. Unfortunately, though, I'm stuck trying to save the output. I can't seem to copy it and right click doesn't do anything.

Ideas?

Upvotes: 3

Views: 4456

Answers (2)

Max Gordon
Max Gordon

Reputation: 5467

The Cairo functions are now included in most R distributions. All you need to do is just specify type="cairo":

png(filename="fn.png", 
    type="cairo",
    units="in", 
    width=5, 
    height=4, 
    pointsize=12, 
    res=96)
...
dev.off()

I wrote a blog-post about the Cairo packages and found out about the new feature through a comment :-)

Upvotes: 2

Paul Hiemstra
Paul Hiemstra

Reputation: 60944

This should work (it does for me using R 2.14 under linux):

cairo_pdf("spam.pdf")
plot(1:10)
dev.off()

and the resulting pdf is in the current work directory. Alternatively, when having the cairo package installed, you can use:

CairoPDF("spam.pdf")
plot(1:10)
dev.off()

to get the same effect.

Information on my system:

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=C                LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fortunes_1.4-2

loaded via a namespace (and not attached):
[1] tools_2.14.1

Upvotes: 3

Related Questions