【问题标题】:Species cartography with R物种制图与 R
【发布时间】:2014-08-25 01:26:51
【问题描述】:

我有一个小数据框(见下文),其中包含 2 个物种“Aganope”和“Brienope”(因子格式)及其地理坐标(Aganope 的 19 行记录和 Brienope 的 12 行记录)。我想制作这个物种的地图,对于第一个,我的代码是:

library(dismo)
str(data)
data
data<-data[1:19,]
str(data)
data
acgeo <- subset(data, !is.na(EST) & !is.na(SOUTH))
dim(acgeo)
acgeo[1:19, c(1:3,1:3)]
# Placer tous les lieux de récolte de Aganope sur le fond de carte bioclimate 5
points(acgeo$EST, acgeo$SOUTH, col="red", pch=21, bg="black", cex=1)

在这段代码中,我根据数据框的行数来选择我的物种(这里是物种“Aganope”,从第 1 行到第 19 行)。我很快就会在这个数据框中有更多的物种。 我的问题是:您是否有一种方法可以通过因子名称(Aganope 或 Brienope)而不是通过对数据框的行编号来映射该物种?

此致

这是我的数据框

Number  Species_name    Collector_name  East    South  
1   Aganope Antila_1186 49.8427778  -15.4327778  
2   Aganope Bar_2365    48.4166667  -17.5500000  
3   Aganope Bern_1760   50.2344444  -15.3352778  
4   Aganope Carl_43 49.7500000  -15.4833333  
5   Aganope Flore_1979  49.7666667  -15.5000000  
6   Aganope Milir_3654  49.7666667  -15.5000000  
7   Aganope Perret_2062 50.4333333  -15.1833333  
8   Aganope Raharim_21401   49.7166667  -16.4500000  
9   Aganope Ralim_109   50.0138889  -15.2869444  
10  Aganope Sciza_1351  49.9500000  -15.6000000  
11  Aganope Sciza_1354  50.0166667  -15.7833333  
12  Aganope Sciza_1370  49.7666667  -15.5000000  
13  Aganope Sciza_2016  49.7666667  -15.5000000  
14  Aganope Serfa_18305 49.8497222  -15.4194444  
15  Aganope Serfa_19221 49.3916667  -17.2833333  
16  Aganope Serfa_28814 49.8833333  -16.8833333  
17  Aganope Serfa_28847 49.8997222  -16.8983333  
18  Aganope Serfa_32138 48.9333333  -19.0333333  
19  Aganope Serfa_32245 48.9333333  -19.0333333  
20  Brienope    Dery_10119  47.1000000  -24.9833333  
21  Brienope    Dery_10210  46.9350000  -25.0486111  
22  Brienope    Dery_4230   46.9983333  -25.0397222  
23  Brienope    Dutz_544    47.0000000  -24.9500000  
24  Brienope    Dutz_756    47.1666667  -24.7833333  
25  Brienope    Rabetra_1835    46.8500000  -25.0666667  
26  Brienope    Rabetra_1892    47.0000000  -24.9500000  
27  Brienope    Rason_5 47.1569444  -24.8127778  
28  Brienope    Ratafika_748    46.9980556  -25.0405556  
29  Brienope    Scott_2473  46.9963889  -25.0416667  
30  Brienope    Serfa_21443 47.2000000  -24.5750000  
31  Brienope    Serfa_28332 46.9330556  -25.0494444  

【问题讨论】:

  • 您没有在此处包含 data 的示例值,因此您的问题不是 reproducible。阅读该链接以获取有关共享示例数据的提示,以便我们可以运行与您相同的代码。你为什么在这里包含library(dismo)?您似乎没有使用该包中的任何功能。我猜你可能只想要acgeo[acgeo[,1]=="Aganope",] 假设物种在第一列。
  • 你试过newdata &lt;- acgeo[acgeo$species == "Aganope",]吗?这类似于@MrFlick 的建议,但如果datagbif 产生的东西(或类似的功能),那么您可以在species 列上设置子集。
  • 提前感谢您的回复。我在上一条消息中发送我的数据框。

标签: r mapping r-factor


【解决方案1】:

是的!

请注意,您不能在不调用绘图之前调用点。您的代码中使用的符号和表中的符号还有一些其他问题。

data <- read.csv() #Your raw data
subset<-data[data$Species_name == "Aganope",]
plot(subset$East, subset$South, col="red", pch=21, bg="black", cex=1)

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 2022-01-17
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    相关资源
    最近更新 更多