Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在r中保存使用循环和mapplot包生成的多个图形? set.seed(1000);DF=数据帧(Lon=runif(20,-93,-87),Lat=runif(20,27,30), Pie1=样本(50,20),Pie2=样本(50,20),Pie3=样本(50,20));头部(DF);NGoM_R_Loops_Save_Maps_Figure - Fatal编程技术网

如何在r中保存使用循环和mapplot包生成的多个图形? set.seed(1000);DF=数据帧(Lon=runif(20,-93,-87),Lat=runif(20,27,30), Pie1=样本(50,20),Pie2=样本(50,20),Pie3=样本(50,20));头部(DF);NGoM

如何在r中保存使用循环和mapplot包生成的多个图形? set.seed(1000);DF=数据帧(Lon=runif(20,-93,-87),Lat=runif(20,27,30), Pie1=样本(50,20),Pie2=样本(50,20),Pie3=样本(50,20));头部(DF);NGoM,r,loops,save,maps,figure,R,Loops,Save,Maps,Figure,在不同的网站上查找了关于r功能的信息后,我找到了问题的解决方案 第一步是在循环的第一部分设置地物选项 set.seed(1000);DF=data.frame(Lon=runif(20,-93,-87),Lat=runif(20,27,30), Pie1=sample(50, 20),Pie2=sample(50, 20),Pie3=sample(50, 20));head(DF);NGoM<-getNOAA.bathy(-93,-87,28,31, resolutio

在不同的网站上查找了关于r功能的信息后,我找到了问题的解决方案

第一步是在循环的第一部分设置地物选项

set.seed(1000);DF=data.frame(Lon=runif(20,-93,-87),Lat=runif(20,27,30),
          Pie1=sample(50, 20),Pie2=sample(50, 20),Pie3=sample(50, 20));head(DF);NGoM<-getNOAA.bathy(-93,-87,28,31, resolution=1,keep=FALSE)
for(i in colnames(DF[,3:5])){
z=DF[,i]
dev.new()
plot(NGoM,col=brewer.pal(n=6,name="Blues"),bg="blue",xaxt="n", yaxt="n",xlab="",ylab="")
map(add=TRUE, col="gray", fill = TRUE)
compassRose(-92, 30.5, rot=0, cex=1)
scalebar(200, xy= c(-90,19.4), type = "bar", divs = 4, cex = 0.7, below = "kilometers", lwd=2, family="Arial")
Ad<-aggregate(list(z=z), list(x=DF$Lon, y=DF$Lat),sum)
draw.bubble(Ad$x, Ad$y, Ad$z,maxradius= 0.25, pch=21, bg=("red"))
legend.bubble(x=-90, y=30.8, z=max(Ad$z), maxradius=0.25, 
          bg="gray78",txt.cex=0.8, pch=21, pt.bg="red")
text(St$Lon,St$Lat,St$Station, family="Arial",cex=0.8, pos=1)
mtext(text="Longitude",side=1, line=2, cex=1)
mtext(text="Latitude",side=2, line=4, cex=1)
degAxis(1, cex.axis=1)
degAxis(2, las=1, cex.axis=1)
box()
ggsave(filename = paste0("C:/Users/xxx/Documents/Fig_", i,.tiff"),plot =last_plot(), device = "png", dpi = 600)
第二步也是最后一步是关闭box()之后的函数

png(paste0("Amap",i,".tiff"),width = 1024, height = 768)
dev.off()