按年份和月份绘制带有温度记录的R型箱线图

按年份和月份绘制带有温度记录的R型箱线图,r,boxplot,R,Boxplot,我有一个包含温度记录的数据集,如: row.names Collection_date temprature col_yr col_mnth 1 1 4-Aug-04 27 2004 8 2 2 9-Aug-04 26 2004 8 3 3 4-Aug-04 27 2004 8 4 4

我有一个包含温度记录的数据集,如:

    row.names   Collection_date temprature  col_yr  col_mnth
    1   1       4-Aug-04          27        2004    8
    2   2       9-Aug-04          26        2004    8
    3   3       4-Aug-04          27        2004    8
    4   4       9-Aug-04          26        2004    8
    5   5       9-Aug-04          26        2004    8
    6   6       9-Aug-04          26        2004    8
...
1031 1031       6-Aug-06          32        2006    8
我想用x轴在R中创建箱线图,如:

1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 ...
        2004                         2005 

这不是一个非常优雅的解决方案,但这是我能想到的唯一一个使您的箱线图具有适当宽度的解决方案

根据您的示例数据:

dat <- read.table(textConnection("row.names   Collection_date temprature  col_yr  col_mnth
  1   1   4-Aug-04    27  2004    8
  2   2   9-Aug-04    26  2004    8
  3   3   4-Aug-04    27  2004    8
  4   4   9-Aug-04    26  2004    8
  5   5   9-Aug-04    26  2004    8
  6   6   9-Aug-04    26  2004    8
  1031 1031   6-Aug-06    32    2006    8"))
最后是月度箱线图:

for(i in seq_along(ax_month)){
    sub_dat <- dat[format(dat$Collection_date, "%m-%Y") == format(ax_month[i], "%m-%Y"),]
    boxplot(sub_dat$temprature, add=TRUE, axes=FALSE, at=i)
    }
<代码>用于(一个月){
非常感谢您提供的详细答案。我尝试了这段代码。我可以绘制网格,但循环会给出一个错误:警告消息:1:In min(x):min没有未丢失的参数;返回InfI最终可以显示它。谢谢。
ax_month <- seq(min(dat$Collection_date),max(dat$Collection_date),"month")
ax_year <- seq(min(dat$Collection_date),max(dat$Collection_date),"year")
plot(NA, xaxt="n",type="n", ylab="Temperature", xlab=NA,
     xlim=range(seq_along(ax_month)), ylim=range(dat$temprature))
axis(3,at=seq_along(ax_month), labels=format(ax_month,"%m"))
mtext(format(ax_year,"%Y"), side=3, line=3, at=seq(1,length(ax_month), by=12))
for(i in seq_along(ax_month)){
    sub_dat <- dat[format(dat$Collection_date, "%m-%Y") == format(ax_month[i], "%m-%Y"),]
    boxplot(sub_dat$temprature, add=TRUE, axes=FALSE, at=i)
    }