【问题标题】:Plot boxplots and line of time series data in R在 R 中绘制箱线图和时间序列数据线
【发布时间】:2014-12-03 19:47:39
【问题描述】:

我想将原位值(线)的时间序列与特殊日期估计值的箱线图结合起来。我试图理解这个“Add a line from different result to boxplot graph in ggplot2”问题,但我的约会让我发疯。有时我只有一个日期的原位值,有时只有估计值,有时两者都有。

我在这里上传了我的数据样本:

http://www.file-upload.net/download-9942494/estimated.txt.html

http://www.file-upload.net/download-9942495/insitu.txt.html

如何创建一个包含两个数据集的图,看起来像这样http://www.file-upload.net/download-9942496/desired_outputplot.png.html 最后?

【问题讨论】:

    标签: r ggplot2 lattice


    【解决方案1】:

    我得到了帮助,现在有了解决方案:

    insitu <- read.table("insitu.txt",header=TRUE,colClasses=c("Date","numeric"))
    est <- read.table("estimated.txt",header=TRUE,colClasses=c("Date","numeric"))
    
    
    insitu.plot <- xyplot(insitu~date_fname,data=insitu,type="l",
              panel=function(x,y,...){panel.grid(); panel.xyplot(x,y,...)},xlab=list(label="Date",cex=2))
    est.plot <- xyplot(estimated~date,data=est,panel=panel.bwplot,horizontal=FALSE)
    both <- insitu.plot+est.plot
    
    update(both,xlim=range(c(est$date,insitu$date_fname))+c(-1,1),ylim=range(c(est$estimated,insitu$insitu)))
    

    【讨论】: