在地图上绘制尺寸取决于类别数量的点 [英] Plotting points on a map with size depending on category count

查看:130
本文介绍了在地图上绘制尺寸取决于类别数量的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带动物标本的数据集,在每个位置我都有多个捕获的不同物种的动物。我想在地图上绘制这些信息,每个点代表一个物种的捕获位置,每个点的大小代表该物种捕获在这个位置的许多动物。除了最后一点,我可以做所有这些,根据每个类别和位置的计数来区分点的大小。

数据:

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

> tapply(test $物种,测试$位置,长度)
位置1位置2位置3位置4
8 23 5 14

标准ggmap图:

  m <-get_map(location = c(lon = 10.6858397,lat = (x = Long,y = Lat,color = 32.7996318),zoom = 7,color =bw)

ggmap(m,extent =normal)+
geom_point Species,size = 2),data = test)



非常感谢@MLavoie。


I have a dataset with animal trappings, where in each location I have multiple animals of several different species captured. I would like to plot this information on a map, such that each point would represent location of trapping of a given species and the size of each point would represent a number of animals of this species trapped in this location. I can do all this except the last point, differentiating point size depending on the counts in each category and location.

Data:

> 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 

Standard ggmap plot:

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)

How do I now change the size of the point depending on how many animals of each species were captured in a location?

解决方案

Got it! Easy-peasy once you know where to look ;-)

Continuing with the object 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)

Thanks a lot @MLavoie.

这篇关于在地图上绘制尺寸取决于类别数量的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆