【问题标题】:qplot and anti-aliasing in RR中的qplot和抗锯齿
【发布时间】:2010-12-26 06:25:23
【问题描述】:

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

ggsave(file="filename.png")

但是我的液晶显示器怎么样?有什么方法可以将显示器上的绘图视为抗锯齿 grpah?

【问题讨论】:

  • 我认为这是你和你的窗口管理器之间的事情。
  • 有没有办法告诉 R 对我的绘图窗口进行抗锯齿处理?

标签: r ggplot2


【解决方案1】:

好的,我刚刚检查过了。我之前的评论错了。 help(x11) 提供了很多详细信息——基于 Cairo 的新设备确实具有可用的抗锯齿功能:

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. 

[...还有更多...]

【讨论】:

  • 好吧,现在这是我的问题:我输入 X11(type="cairo") 时出现错误我收到“X11 中的错误(type = "cairo"):未使用的参数(type = "cairo")" 我已经加载了 cairo 但不知道如何更改我的 X11。我在 Win XP 上使用 R 2.9.2。我是否需要废弃整个系统并让 Mac 为我的显示器提供抗锯齿功能?
  • 我有点担心那部分。我知道 Cairo 来自 Gnome / Gtk 并且在 Linux 上很熟悉,但我认为这是跨平台的。在 XP 上的 R 会话中调用 capabilities() 会得到什么?我在最后有一个 'cairo' TRUE。
  • 我得到了错误,但无论如何感谢,非常有趣的旅程。稍后我将在 Ubuntu 上试用它。再次感谢您的调查。
  • 我的荣幸。 Cairo 具有抗锯齿、Alpha 混合等所有功能,但它也有渲染速度较慢的代价。
  • 啊,我看到菲利克斯有货了。因此,在 Windows 上,您需要其中一个 Cairo 软件包,它要求您获得 Gtk+ 以获取底层技术。有道理。
【解决方案2】:

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

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

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

【讨论】:

  • 我在带有 R 3.1.1 64 位的 Windows 7 上安装了 Cairo,而无需安装 GTK+。抗锯齿很好。
【解决方案3】:

正如其他人所提到的,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

【讨论】:

    【解决方案4】:

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

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

    如指定here

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

    【讨论】:

    • 我建议改用type = "cairo"
    猜你喜欢
    • 2014-02-18
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-07-10
    • 2016-06-28
    • 2011-07-05
    • 2014-03-19
    相关资源
    最近更新 更多