2015-01-21 132 views
0

我有這段代碼,它假設寫一個情節包含許多小的子情節到一個文件。R寫入文件劇情由子情節組成

par(mar=c(1,1,1,1)) 
    par(mfrow=c(3,3)) 

    filepath <- paste(getwd(),'/','BP_',product_name,'.jpg',sep="") 
    jpeg(filepath) 

    boxplot(normalized.price_shipping~rank, data=data.selected, main=toupper("Normalized Price By Rank Levels"), font.main=3, cex.main=1.2, xlab="Rank Levels", ylab="Price+Shpping", font.lab=3, col="darkgreen") 
    #dev.off() 

    #filepath <- paste(getwd(),'/','BP_normalized.seller_feedback_score_',product_name,'.jpg',sep="") 
    #jpeg(filepath) 
    boxplot(normalized.seller_feedback_score~rank, data=data.selected, main=toupper("normalized.seller_feedback_score By Rank Levels"), font.main=3, cex.main=1.2, xlab="Rank Levels", ylab="normalized.seller_feedback_score", font.lab=3, col="darkgreen") 
    #dev.off() 

    #filepath <- paste(getwd(),'/','BP_normalized.seller_positive_feedback_percent~rank_',product_name,'.jpg',sep="") 
    #jpeg(filepath) 
    boxplot(normalized.seller_positive_feedback_percent~rank, data=data.selected, main=toupper("normalized.seller_positive_feedback_percent By Rank Levels"), font.main=3, cex.main=1.2, xlab="Rank Levels", ylab="normalized.seller_positive_feedback_percent", font.lab=3, col="darkgreen") 
    #dev.off() 

    #filepath <- paste(getwd(),'/','BP_keywords_title_assoc~rank_',product_name,'.jpg',sep="") 
    #jpeg(filepath) 
    boxplot(keywords_title_assoc~rank, data=data.selected, main=toupper("keywords_title_assoc By Rank Levels"), font.main=3, cex.main=1.2, xlab="Rank Levels", ylab="keywords_title_assoc", font.lab=3, col="darkgreen") 
    #dev.off() 

    #filepath <- paste(getwd(),'/','BP_log10_seller_feedback_score~rank_',product_name,'.jpg',sep="") 
    #jpeg(filepath) 
    boxplot(log10(seller_feedback_score)~rank, data=data.selected, main=toupper("seller_log10_feedback_score By Rank Levels"), font.main=3, cex.main=1.2, xlab="Rank Levels", ylab="seller_feedback_score", font.lab=3, col="darkgreen") 


    dev.off() 

但是,在寫入文件系統的文件中,我只能看到我需要看到的5個箱形圖中的最後一個圖。 任何想法爲什麼?

+0

此答案可能有所幫助:http://stackoverflow.com/q/13175556/1414455 – tchakravarty 2015-01-21 06:16:56

+0

找不到我的答案。我認爲我的問題是不同的 - 我可以成功地看到RStudio中的所有子圖,但是當寫入圖時,只有最後一個圖顯示在文件中 – user3628777 2015-01-21 06:26:42

回答

1

我想,這是因爲你應該先創建jpeg文件,然後用par函數。

filepath <- paste(getwd(),'/','BP_',product_name,'.jpg',sep="") 
    jpeg(filepath) 

par(mar=c(1,1,1,1)) 
par(mfrow=c(3,3)) 
etc.