Problem:
R的圖形輸出其畫質會變得不是很清晰等問題.
Analysis:
R中可以採用多種不同輸出格式, 其中以 pdf 格式較佳, 如果 tiff , eps 有做參數調整, 應該也是不錯的選擇, 詳細設定參考 ?tiff , ?pdf 指令。在 RStudio 軟體中亦可直接選取 Export \ Save Plot as Image ... 輸出圖檔, 參考以下 R codes.
graphics-export.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# title: graphics export | |
# date: 2013.5.24 | |
# author: Ming-Chang Lee | |
# install.packages("openair") | |
library(openair) | |
pdf("openair.pdf") | |
polarFreq(mydata, pollutant = "so2", type = "year", statistic = "weighted.mean", min.bin = 2) | |
dev.off() | |
png("openair.png", width = 1024, height = 768) | |
polarFreq(mydata, pollutant = "so2", type = "year", statistic = "weighted.mean", min.bin = 2) | |
dev.off() | |
tiff("openair.tiff", width = 1024, height = 768) | |
polarFreq(mydata, pollutant = "so2", type = "year", statistic = "weighted.mean", min.bin = 2) | |
dev.off() | |
setEPS() | |
postscript("openair.eps") | |
polarFreq(mydata, pollutant = "so2", type = "year", statistic = "weighted.mean", min.bin = 2) | |
dev.off() | |
# end |
pdf原圖

pdf 放大200%

我有個問題想問一下版主 此圖示透過套件產生,再加以輸出
回覆刪除那要我用plot畫了一個散佈圖,要如何進行pdf或png的輸出呢?
請版主給我一些詳細建議或可能寫法
Hi Chih-Wei,
回覆刪除將 plot() 寫在 pdf() 與 dev.off() 中間即可, 參考以下範例, 開啟 iris.scatter.pdf 檔案即可瀏覽結果:
pdf("iris.scatter.pdf")
plot(iris$Petal.Length, iris$Petal.Width,
col=iris$Species,
main="iris - scatter plot-2015")
legend("topleft",
legend=c("setosa", "versicolor", "virginica"),
col=1:3,
pch=1)
dev.off()
# end