20

我正在使用 ggplot2 库并且正在使用 qplot 命令 我知道我可以在 qplot 之后使用以下命令将输出保存为抗锯齿图像文件

ggsave(file="filename.png")

但是我的液晶显示器怎么样?有什么方法可以在显示器上看到一个抗锯齿 grpah 的情节?

4

4 回答 4

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!

更多的

于 2012-02-05T23:31:17.323 回答
14

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

Gtk+ 2.12.9 Runtime Environment Revision 2http://gladewin32.sourceforge.net/下载并安装

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

于 2009-12-14T05:20:13.657 回答
5

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

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

在这里指定。

但是出于什么目的,您想要“在显示器上看到图形作为抗锯齿图”或“抗锯齿我的绘图窗口”?如果您的意思是在 RStudio 的绘图窗口(选项卡)中,我不确定是否可以这样做,它基本上只是作为预览。我建议您将图形保存到文件中,然后使用此文件显示它或用于任何其他目的。

于 2015-10-13T12:54:36.920 回答
4

好的,我刚查了。我之前的评论错了。从help(x11)那里可以获得很多细节——基于开罗的新设备确实具有抗锯齿功能:

x11 包:grDevices R 文档

X 窗口系统图形

描述:

 ‘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. 

[...和更多...]

于 2009-12-14T01:36:01.263 回答