我想用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并按行过滤并以某种方式汇总类别。还是你觉得呢?您认为这是呈现此数据的最佳方法吗?
答案 0 :(得分: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")
您的数据/代码有几个问题:
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).