2011-05-16 21 views
29

有沒有辦法從Windows版本的R中繪製反鋸齒圖形?正如你可以從[R打印圖形反鋸齒Mac版下方的兩個版本看.... Mac VersionWindows下的R圖形中的反鋸齒(按照Mac)

....而同時Windows版本的消除鋸齒的文本,它不抗混疊實際圖形,從提升點可以看出,與電網: Windows Version

這裏是代碼的方式:

library(scatterplot3d) 
attach(mtcars) 
s3d <-scatterplot3d(wt,disp,mpg, pch=16, highlight.3d=TRUE, 
    type="h", main="3D Scatterplot") 
fit <- lm(mpg ~ wt+disp) 
s3d$plane3d(fit) 

我需要儘可能高的質量,爲Web頁的出版物。我正在運行Windows 7並從RBloomberg提取數據,而這些數據僅適用於Windows。

回答

18

這很可能取決於每個平臺上渲染引擎的細節,這些細節可能很難修改。我的建議(未經測試,由於缺乏時間和訪問Windows):

  • 安裝cairoDevice包,然後用Cairo_png()。根據文檔:
This functions the same as any other R graphics device. You may 
use the conventional plot commands and expect essentially the same 
output, except that everything is anti-aliased (similar to other 
vector-based devices like Quartz). Alpha-blending is supported, as 
is enhanced interactivity via ‘getGraphicsEvent’. The device 
should work the same across all supported platforms (Mac, Windows, 
and Linux). 
  • 呈現在更高的分辨率(來自R爲PDF或輸出數據)的PNG和使用的ImageMagick(convert)或其他工具來獲得反鋸齒版本,你需要。
+0

你也可以輸出爲開羅的SVG,它可以提供出色的輸出。 – James 2011-05-17 09:58:13

+0

我有(最後)得到這個工作。但是有沒有什麼辦法可以保存文件或從屏幕圖像複製和粘貼,就像使用標準設備一樣?謝謝。 – 2011-08-11 20:34:08

+0

一旦安裝了cairoDevice,您可以簡單地調用Cairo()獲取在MS Windows下反鋸齒的繪圖窗口。 – 2015-10-04 08:12:09

9

使用矢量設備,如pdf。首先確保你有這樣的能力,所以並不奇怪,capabilities函數是檢查的內容。如果你有PDF,然後只是這樣做:

pdf(file="out_graph.pdf") 
s3d <-scatterplot3d(wt,disp,mpg, pch=16, highlight.3d=TRUE, 
    type="h", main="3D Scatterplot") 
fit <- lm(mpg ~ wt+disp) 
s3d$plane3d(fit) 
dev.off() 

爲網絡輸出的另一種可能是PNG()圖形設備。儘管它是光柵格式,但它在緊湊性和網頁瀏覽器兼容性方面獲得了很高的評價。

+1

@DWin:OP給出的圖片爲png格式... – 2011-05-16 21:45:21

+0

@Joris ...我認爲SO界面可能自己選擇了一種格式。我不認爲這需要我的PDF格式,並在上傳時保留它們。 (但我可能在這裏錯誤。) – 2011-05-16 22:08:56

+0

OP說他需要他們進行網頁顯示,所以他可能需要一個光柵格式。 – 2011-05-16 22:34:47

1

你並不需要通過文件去,你可以簡單的安裝cairoDevice由Ben Bolker的建議,然後調用開羅()函數,這將給你在Windows下完全消除鋸齒圖形窗口(慢雖然)。

7

安裝cairoDevice不再需要使用開羅png設備。打開設備時,您現在可以指定type='cairo'。比較以下幾點:

png('test1.png', 500, 500) 
s3d <- scatterplot3d(wt,disp,mpg, pch=16, highlight.3d=TRUE, 
        type="h", main="3D Scatterplot") 
fit <- lm(mpg ~ wt+disp) 
s3d$plane3d(fit) 
dev.off() 

enter image description here

png('test2.png', 500, 500, type='cairo') 
s3d <- scatterplot3d(wt,disp,mpg, pch=16, highlight.3d=TRUE, 
        type="h", main="3D Scatterplot") 
fit <- lm(mpg ~ wt+disp) 
s3d$plane3d(fit) 
dev.off() 

enter image description here

我運行Windows 8.1,和64位R 3.2.2。