我想用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并按行过滤并以某种方式对类别求和。或者您怎么看?你认为这是展示这些数据的最佳方式吗?
欢迎来到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")
您的数据/代码存在一些问题:
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).