在地图上绘制点,其大小取决于类别计数

时间:2016-01-20 13:39:24

标签: r ggplot2 mapping 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)

标准ggmap图:

Button[] Tombol = new Button[]{B1, B2, B3}
int counterbutton = 0;
foreach (Button btn in Tombol) //I have problem here. I don't know how to solve
{
  if(btn.BackColor == Color.Red)
  counterbutton++;
}

Trapping locations on a map

我现在如何根据每个物种在一个地点捕获的动物数量来改变点的大小?

1 个答案:

答案 0 :(得分:1)

知道了!一旦你知道在哪里看,就会轻松自如; - )

继续对象测试:

> 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)

Map of trapping locations where the size of each point now corresponds to the number of samples from each location

非常感谢@MLavoie。