2009-12-13 42 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窗口(標籤)那樣,我不確定這是否可以完成,它基本上只是作爲預覽。我建議你將圖表保存到一個文件中,然後使用這個文件來顯示它或用於其他目的。