物种丰度图与ggmap - >如何调整点的大小足够

问题描述 投票:0回答:1

我想用ggmap创建一个地图,在那里你可以看到哪些物种在哪里找到了多少次。 “多少”应该由点/气泡的大小来表示。但我可以想象通过颜色(如热图)表示也可以,然后通过塑造点来分离物种。到目前为止我所得到的:对于背景地图:

B<-get_map(location = c(lon = -56.731405, lat =-61.4831206),
           zoom = 6, 
           scale = "auto",
           maptype = c("terrain"),
           source = c("google"))

对于散点图:

D<-ggmap(B) + 
geom_point(data=Anatomy,
aes(x=Anatomy$Longitude,y=Anatomy$Latitude,
color=Species,
size=??) +
scale_size_continuous(range=c(1,12))

我的数据=解剖学看起来像这样:

  Species Lat Long Station
1       A  50   60       I
2       A  50   60       I
3       A  40   30      II
4       B  50   60       I
5       B  40   30      II
6       C  50   60       I
7       C  10   10     III
8       C  10   10     III
9       C  40   30      II

我的想法是使用dplyr并按行过滤并以某种方式对类别求和。或者您怎么看?你认为这是展示这些数据的最佳方式吗?

r ggplot2 ggmap bubble-chart
1个回答
0
投票

欢迎来到StackOverflow!为了帮助人们帮助您,您应该努力提供reproducible example。例如,这里将是您的数据的一个小代码摘录:

library(tidyverse)
Anatomy <- tribble(~Species,  ~Lat, ~Long, ~Station,
                "A",  50,   60,       "I",
                "A",  50,   60,       "I",
                "A",  40,   30,      "II",
                "B", 50,   60,       "I",
                "B",  40,   30,      "II") 

您的数据/代码存在一些问题:

  • 投影:您很可能需要重新投影数据。只需查看坐标,您的点数就是50,60,而地图显示的是-50,-60。找出投影,并使用包st_transform中的sf
  • 引用变量:您不需要再次调用数据框,如Anatomy$Latitude。只需使用Latitude。加上latitude实际上是你的数据中的lat!?
  • 聚合:我建议只使用count()函数来查看每个站点的观测数量。

这是一段代码。注意我只是反转(60,50)到(-60,-50)这显然是错误的!

library(ggmap)
#> Loading required package: ggplot2
#> Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
#> Please cite ggmap if you use it! See citation("ggmap") for details.
library(tidyverse)

B<-get_map(location = c(lon = -56.731405, lat =-61.4831206),
           zoom = 6, 
           scale = "auto",
           maptype = c("terrain"),
           source = c("google"))

library(tidyverse)
Anatomy <- tribble(~Species,  ~Lat, ~Long, ~Station,
                "A",  50,   60,       "I",
                "A",  50,   60,       "I",
                "A",  40,   30,      "II",
                "B", 50,   60,       "I",
                "B",  40,   30,      "II") 

Anatomy_clean <- Anatomy %>% 
  mutate_at(c("Lat", "Long"), funs(-1*.)) %>% 
  count(Species, Lat, Long, Station)
#> Warning: funs() is soft deprecated as of dplyr 0.8.0
#> please use list() instead
#> 
#> # Before:
#> funs(name = f(.)
#> 
#> # After: 
#> list(name = ~f(.))
#> This warning is displayed once per session.


ggmap(B) + 
  geom_point(data=Anatomy_clean,
             aes(x= Lat,y=Long, color=Species, size= n)) +
  scale_size_continuous(range=c(1,12))
#> Warning: Removed 2 rows containing missing values (geom_point).

© www.soinside.com 2019 - 2024. All rights reserved.