2009-12-13 41 views
16

我使用GGPLOT2库和抗锯齿我与qplot命令 我知道我可以通过我的qplot后使用以下命令我的输出保存为抗锯齿的图像文件加工qplot和R中

ggsave(file="filename.png") 

但如何对我的液晶显示器?有没有办法在显示器上看到一个图形作为反锯齿grpah?

+0

我认为这是你和你的窗口管理器之间。 – 2009-12-13 23:30:01

+7

有没有办法告诉R来消除我的图形窗口的混淆? – Mark 2009-12-14 00:23:37

回答

13

在Windows上,没有内置的抗锯齿功能。我不知道它是否计划在未来发布。你可以从任一cairoDeviceCairo包一个设在开罗的图形设备;但是,您将需要安装GTK+第一:

下载,然后从http://gladewin32.sourceforge.net/

安装Gtk+ 2.12.9 Runtime Environment Revision 2另一种办法是通过JGRhttp://jgr.markushelbig.org/)使用基于Java的图形。另外一个Qt基于设备正在发展,我想。

+0

太棒了,非常感谢你 – Mark 2009-12-14 07:21:17

+2

我安装了Cairo,而不必在安装了R 3.1.1 64位的Windows 7上安装GTK +。 Antialising很好。 – jnm2 2014-07-31 15:15:53

3

好吧,我只是检查。我在之前的评论中错了。从help(x11)其中很多细节是可用 - 新开罗的设备确实有抗锯齿提供:

X11包:grDevices R文件

X Window系统图形

说明:

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

[...等等...]

+0

好吧,现在这里是我的问题:当我键入X11(type =“cairo”)时出现错误我得到“X11错误(type =”cairo“):未使用的参数(s)(type =”cairo“) “我有cairo加载,但不知道我可以如何改变我的X11。我在Win XP上使用R 2.9.2。我是否需要垃圾我的整个系统,并让我的显示器上的反锯齿Mac? – Mark 2009-12-14 02:47:39

+0

我很担心那部分。我知道开罗来自Gnome/Gtk,并且在Linux上是正确的,但我认为这是跨平台的。当你在XP的R会话中调用'capabilities()'时,你会得到什么?最后,我有一个'cairo'TRUE。 – 2009-12-14 03:02:30

+0

我得到FALSE,但无论如何,非常有趣的旅程。稍后我会在Ubuntu上试用它。再次感谢您的关注。 – Mark 2009-12-14 06:53:53

12

正如其他人所说,R内置在Windows图形设备没有做抗锯齿。但是现在很容易安装开罗的图形设备。

在R控制台:

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

测试:

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

More

2

如果您已经安装了开罗(见其他答案),将其保存为一个抗别名PNG,只需将您的代码更改为:

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

如规定here

但是为了什么目的,你想“在监视器上看到一个图形作为反锯齿图”或“反别名我的图形窗口”?如果你的意思是像RStudio中的Plots窗口(标签)那样,我不确定这是否可以完成,它基本上只是作为预览。我建议你将图表保存到一个文件中,然后使用这个文件来显示它或用于其他目的。