簡體   English   中英

在地圖上繪制點,其大小取決於類別計數

[英]Plotting points on a map with size depending on category count

我有一個包含動物誘捕的數據集,在每個位置我都捕獲了幾種不同物種的多只動物。 我想在地圖上繪制此信息,以便每個點都代表給定物種的誘捕位置,每個點的大小都代表該位置誘捕的該物種的許多動物。 除了最后一點,我可以做所有這些事情,根據每個類別和位置中的計數來區分點的大小。

數據:

> test
Species  Location      Long      Lat
1  Species1 Location4 13.179328 32.83438
2  Species1 Location4 13.179328 32.83438
3  Species1 Location4 13.179328 32.83438
4  Species1 Location4 13.179328 32.83438
5  Species1 Location4 13.179328 32.83438
6  Species1 Location4 13.179328 32.83438
7  Species1 Location4 13.179328 32.83438
8  Species1 Location4 13.179328 32.83438
9  Species1 Location4 13.179328 32.83438
10 Species1 Location4 13.179328 32.83438
11 Species1 Location4 13.179328 32.83438
12 Species1 Location4 13.179328 32.83438
13 Species1 Location4 13.179328 32.83438
14 Species1 Location4 13.179328 32.83438
15 Species1 Location2 13.857541 32.71680
16 Species1 Location2 13.857541 32.71680
17 Species1 Location2 13.857541 32.71680
18 Species1 Location1  7.584970 33.77976
19 Species1 Location1  7.564263 33.81079
20 Species1 Location1  7.555380 33.79994
21 Species2 Location1  7.542248 33.79943
22 Species2 Location1  7.562118 33.79340
23 Species2 Location1  7.542248 33.79943
24 Species2 Location1  7.555380 33.79994
25 Species2 Location1  7.542248 33.79943
26 Species2 Location3 11.377850 33.20891
27 Species2 Location3 11.377850 33.20891
28 Species2 Location3 11.377850 33.20891
29 Species2 Location3 11.377850 33.20891
30 Species2 Location3 11.377850 33.20891
31 Species1 Location2 13.834581 32.72319
32 Species1 Location2 13.834581 32.72319
33 Species1 Location2 13.834581 32.72319
34 Species1 Location2 13.834581 32.72319
35 Species1 Location2 13.834581 32.72319
36 Species1 Location2 13.834581 32.72319
37 Species1 Location2 13.834581 32.72319
38 Species1 Location2 13.834581 32.72319
39 Species1 Location2 13.834581 32.72319
40 Species1 Location2 13.834581 32.72319
41 Species1 Location2 13.834581 32.72319
42 Species1 Location2 13.834581 32.72319
43 Species1 Location2 13.834581 32.72319
44 Species1 Location2 13.834581 32.72319
45 Species1 Location2 13.834581 32.72319
46 Species1 Location2 13.834581 32.72319
47 Species1 Location2 13.834581 32.72319
48 Species1 Location2 13.834581 32.72319
49 Species1 Location2 13.834581 32.72319
50 Species1 Location2 13.834581 32.72319

> tapply(test$Species,test$Location,length)
Location1 Location2 Location3 Location4 
        8        23         5        14 

標准ggmap圖:

m<-get_map(location=c(lon=10.6858397, lat=32.7996318), zoom=7, color="bw")

ggmap(m, extent = "normal") +
  geom_point(aes(x = Long, y = Lat, colour = Species, size = 2), data = test)

捕獲地圖上的位置

現在,我如何根據某個位置捕獲的每種物種的多少動物來更改點的大小?

得到它了! 一旦知道要去哪里就輕松了;-)

繼續進行對象測試:

> library(doBy)
> tdata<-summaryBy(test~Location+Species+Long+Lat, data=test, FUN=length)
> tdata

    Location  Species      Long      Lat test.length
1  Location1 Species1  7.555380 33.79994           1
2  Location1 Species1  7.564263 33.81079           1
3  Location1 Species1  7.584970 33.77976           1
4  Location1 Species2  7.542248 33.79943           3
5  Location1 Species2  7.555380 33.79994           1
6  Location1 Species2  7.562118 33.79340           1
7  Location2 Species1 13.834581 32.72319          20
8  Location2 Species1 13.857541 32.71680           3
9  Location3 Species2 11.377850 33.20891           5
10 Location4 Species1 13.179328 32.83438          14

> ggmap(m, extent = "normal") +
+     geom_point(aes(x = Long, y = Lat, colour = Species, size = test.length), data = data)

現在每個點的大小與每個位置的樣本數相對應的捕獲位置圖

非常感謝@MLavoie。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM