【问题标题】:R Write to file Plot consists of sub plotsR写入文件情节由子情节组成
【发布时间】:2015-01-21 06:12:22
【问题描述】:

我有这段代码,假设要编写一个由许多小子图组成的图。

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 个箱形图中的最后一个图。 知道为什么吗?

【问题讨论】:

  • 这个答案可能会有所帮助:stackoverflow.com/q/13175556/1414455
  • 在那里找不到我的答案。我认为我的问题不同 - 我可以成功地看到 RStudio 中的所有子图,但是当将图写入文件时,文件中只显示最后一个图

标签: r plot par


【解决方案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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 2019-12-05
    • 1970-01-01
    • 2018-03-30
    • 2018-10-02
    • 1970-01-01
    相关资源
    最近更新 更多