0

我有一个数据框,其中包含 500 个物种和 25,000 个对各种物种的局部观测点。我想制作单个物种点图,地图上的每个点都是物种的一次出现。因为要制作的地图太多了,所以我需要循环执行此操作。这就是我到目前为止所拥有的。

#loop for making species map 1.1
species <- levels(raw$SpCode)
for(i in 1:length(species))  
            {
            #open the file for writing
             pdf(species[i], file=".pdf", width=5, height=4)
             plot (wrld_simpl, xlim=c(-100,-55), ylim=c(23,63), axes=TRUE, col='light grey')
             box() #adds box around map
             title(main=species[i]) #adds main title to map which should be the species name associated with the data
             points(raw, species[i]$longitude, species[i]$latittude, col='black', pch=21, bg="red", cex=0.85)
             dev.off()
             }

我得到的主要错误输出是:

“Error in species[i]$longitude : $ operator is invalid for atomic vectors
In addition: Warning message:
‘mode(onefile)’ differs between new and previous==> NOT changing ‘onefile’"

任何有关如何推进这方面的建议都会有所帮助。我正在使用 maptools 包来尝试制作这些地图。

干杯,以色列

4

1 回答 1

0

循环制作物种地图1.2另存为pdf

感谢 Joran 帮我解决这个问题!:)

species <- levels(raw$SpCode)
for(i in 1:length(species))  
            {
            #open the file for writing
             pdf(paste0(species[i],".pdf"),width=5,height=4)
             plot (wrld_simpl, xlim=c(-100,-55), ylim=c(23,63), axes=TRUE, col='light grey')
             box() #adds box around map
             title(main=species[i]) #adds main title to map which should be the species name associated with the data
             points(raw$longitude[raw$SpCode == species[i]],raw$latitude[raw$SpCode == species[i]], col='black', pch=21, bg="red", cex=0.85)
             dev.off()
             }
于 2013-01-31T23:13:25.657 回答