Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qplot and anti-aliasing in R

Tags:

r

ggplot2

I am using ggplot2 library and am working with the qplot command I know I can save my output as an anti-aliased image file by using the following command after my qplot

ggsave(file="filename.png")

But how about my LCD display? is there any way to see a plot on the monitor as anti-aliased grpah?

like image 624
Mark Avatar asked Dec 13 '09 22:12

Mark


3 Answers

As others have mentioned, R's built-in Windows graphics device does not do anti-aliasing. But nowadays it's easy to install the Cairo graphics device which does.

At the R console:

install.packages('Cairo',,'http://www.rforge.net/')

To test:

plot(rnorm(1000)) # non-antialiased (on Windows)
library('Cairo')
CairoWin()
plot(rnorm(1000)) # antialiased!

More

like image 195
jwfearn Avatar answered Oct 04 '22 18:10

jwfearn


On Windows, there is no built-in anti-aliasing. I don't know whether it is planned for future releases or not. You can get a Cairo-based graphics device from either the cairoDevice or Cairo packages; however, you will need to install GTK+ first:

Download and install Gtk+ 2.12.9 Runtime Environment Revision 2 from http://gladewin32.sourceforge.net/

Another option would be to use Java-based graphics through JGR (http://jgr.markushelbig.org/). Also a Qt-based device is under development, I think.

like image 22
Felix Andrews Avatar answered Oct 04 '22 16:10

Felix Andrews


If you have Cairo installed (see the other answers), to save it as an anti-aliased PNG, just change your code to:

ggsave(file="filename.png", type="cairo-png")

as specified here.

But for what purpose do you want to "see a plot on the monitor as anti-aliased graph" or "anti-alias my plot windows"? If you mean like in the Plots window (tab) in RStudio, I am not sure that can be done, it serves basically just as a preview. I suggest you save the graph to a file and then use this file to display it or for any other purpose.

like image 5
Melkor.cz Avatar answered Oct 04 '22 16:10

Melkor.cz