2016-06-09 47 views
0

我試圖生成R.修復有R

我使用pdf()pie()dev.off()一個文件PDF空白的PDF頁面,但在我的PDF結果所有的頁面都是空白。

這是我的R代碼裏面:

library(jsonlite) 
jsons_path <- "C:/color_uses/jsons" 
setwd(jsons_path) 
jsons <- list.files(jsons_path, pattern=NULL, all.files=FALSE, 
     full.names=FALSE) 

pdf(file=paste(c("../pngs/pies.pdf"), collapse = ''), width = 1000, height = 600, onefile=T) 
for(j in jsons){ 
color_uses <- fromJSON(j) 
color_uses <- lapply(color_uses, function(x) { 
    x[sapply(x, is.null)] <- NA 
    unlist(x) 
}) 
color_uses <- do.call("rbind", color_uses) 
color_uses <- as.data.frame(color_uses) 
if (is.vector(color_uses$probability)) { 
color_uses$prob <- color_uses$probability 
color_uses$hex <- rownames(color_uses) 
color_uses <- color_uses[order(color_uses$probability),] 

artist_name <- gsub(".json", "", j) 

pie(color_uses$prob, col=color_uses$hex, labels=NA, main=paste(c("Colors of: ", artist_name), collapse= ''), 
    cex.lab=2, cex.axis=2, cex.main=2, cex.sub=2) 
} 

} 
dev.off() 

我能做些什麼來解決這個空白頁,這樣我就可以使每個頁面上的餅圖?

+2

你的寬度和高度是非常高的。單位是英寸。 沒有'pdf(....)'和'dev.off()'的工作代碼? –

+0

謝謝,我認爲寬度和高度是很大的,是的。我現在有: pdf(file = paste(c(「../ pngs/pies.pdf」),collapse =''),width = 10,height = 10,onefile = T) 空白頁消失了;) –

回答

0

考慮到單位被指定爲英寸,您的寬度和高度非常高。默認值是7英寸。所以你應該使用較小的值:

pdf(file = "path_to_your_file.pdf", width = 10, height = 6, onefile=TRUE) 

# your code here 

dev.off()