jpeg()函数解析为循环R时的空白图

时间:2019-01-10 12:57:15

标签: r loops plot jpeg

当我将绘图解析为循环时,会发生奇怪的事情。所有图解均已保存,但完全空白。 Seasons是向量,AllYear_Avg是列表。两者的长度相同。没有错误返回。

for (i in 1:length(Seasons)){
  jpeg(paste0(PathMap,Seasons[i],"AllYears.jpg"),res=300,width=10,height=13,units="cm")
  plt <- levelplot(AllYear_Avg[[i]] ~ lon * lat, 
                   xlim=c(-124.5,-114), ylim=c(32,42.5), 
                   data=grid, margin = F, at=cutpts, cuts=11, 
                   pretty=TRUE, par.settings = mapTheme,
                   col.regions=colorRampPalette(c("light blue","blue", "red")),
                   main=paste0(Var1description," \n",Seasons[i]," ",Yr))
  plt + layer(sp.lines(world.outlines.sp, col = "black", lwd = 0.5))
  dev.off()
}

相反,当我删除顶部和底部的行并将[i]替换为[1](如下所示)时,它工作正常,并且将图另存为jpeg并带有正确的图(不像循环中那样为空白)。如果没有可重现的示例,是否可以判断上述循环出了什么问题?

jpeg(paste0(PathMap,Seasons[1],"AllYears.jpg"),res=300,width=10,height=13,units="cm")
plt <- levelplot(AllYear_Avg[[1]] ~ lon * lat, 
                 xlim=c(-124.5,-114), ylim=c(32,42.5), 
                 data=grid, margin = F, at=cutpts, cuts=11, 
                 pretty=TRUE, par.settings = mapTheme,
                 col.regions=colorRampPalette(c("light blue","blue", "red")),
                 main=paste0(Var1description," \n",Seasons[1]," ",Yr))
plt + layer(sp.lines(world.outlines.sp, col = "black", lwd = 0.5))
dev.off()

0 个答案:

没有答案