R中的qplot和抗锯齿

时间:2009-12-13 22:55:24

标签: r ggplot2

我正在使用ggplot2库并正在使用qplot命令 我知道我可以在qplot

之后使用以下命令将输出保存为消除锯齿的图像文件
ggsave(file="filename.png")

但我的液晶显示器怎么样?有没有办法在显示器上看到一个抗锯齿的格子?

4 个答案:

答案 0 :(得分:16)

正如其他人所提到的,R的内置Windows图形设备不会做抗锯齿。但是现在安装Cairo图形设备很容易。

在R控制台:

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

测试:

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

More

答案 1 :(得分:14)

在Windows上,没有内置的抗锯齿功能。我不知道是否计划在未来发布。您可以从cairoDeviceCairo软件包中获取基于Cairo的图形设备;但是,您需要先安装GTK+

http://gladewin32.sourceforge.net/

下载并安装Gtk+ 2.12.9 Runtime Environment Revision 2

另一种选择是通过JGRhttp://jgr.markushelbig.org/)使用基于Java的图形。我认为,基于Qt的设备正在开发中。

答案 2 :(得分:4)

好的,我刚刚检查过。我之前的评论错了。从help(x11)可以获得大量详细信息 - 新的基于开罗的设备确实具有抗锯齿效果:

  

x11包:grDevices   R文档

     

X Window System Graphics

     

说明

 ‘X11’ starts a graphics device driver for the X Window System
 (version 11).  This can only be done on machines/accounts that
 have access to an X server.

 ‘x11’ is recognized as a synonym for ‘X11’.
     

用法:

 X11(display = "", width, height, pointsize, gamma, bg, canvas,
     fonts, xpos, ypos, title, type, antialias)

 X11.options(..., reset = FALSE)
     

参数:

     

[...]

 fonts: X11 font description strings into which weight, slant and
      size will be substituted.  There are two, the first for fonts
      1 to 4 and the second for font 5, the symbol font.  See
      section ‘Fonts’. 
     

[...]

 antialias: for cairo types, the typeof anti-aliasing (if any) to be
      used.  One of ‘c("default", "none", "gray", "subpixel")’. 
     

[...]

     

详细说明:

 The defaults for all of the arguments of ‘X11’ are set by
 ‘X11.options’: the ‘Arguments’ section gives the ‘factory-fresh’
 defaults.

 The initial size and position are only hints, and may not be acted
 on by the window manager.  Also, some systems (especially laptops)
 are set up to appear to have a screen of a different size to the
 physical screen.

 Option ‘type’ selects between two separate devices: R can be built
 with support for neither, ‘type = "Xlib"’ or both.  Where both are
 available, types ‘"cairo"’ and ‘"nbcairo"’ offer

    * antialiasing of text and lines.

    * translucent colours.

    * scalable text, including to sizes like 4.5 pt.

    * full support for UTF-8, so on systems with suitable fonts you
      can plot in many languages on a single figure (and this will
      work even in non-UTF-8 locales).  The output should be
      locale-independent.

 ‘type = "nbcairo"’ is the same device as ‘type="cairo"’ without
 buffering: which is faster will depend on the X11 connection.
 Both will be slower than ‘type = "Xlib"’, especially on a slow X11
 connection as all the rendering is done on the machine running R
 rather than in the X server.

 All devices which use an X11 server (including the ‘type = "Xlib"’
 versions of bitmap devices such as ‘png’) share internal
 structures, which means that they must use the same ‘display’ and
 visual.  If you want to change display, first close all such
 devices. 
     

[...以及......]

答案 3 :(得分:4)

如果您安装了Cairo(请参阅其他答案),要将其另存为消除锯齿的PNG,只需将您的代码更改为:

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

指定here

但是你想用于什么目的"在监视器上看到一个作为抗锯齿图的图表"或"反别名我的情节窗口"?如果您的意思是在RStudio的Plots窗口(选项卡)中,我不确定是否可以完成,它基本上只是作为预览。我建议您将图表保存到文件中,然后使用此文件显示它或用于任何其他目的。