-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_transform.R
58 lines (37 loc) · 1.28 KB
/
04_transform.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
###
library(tidyverse)
library(ggmap)
library(mapdata)
### count data
pups_wide <- read_csv("SSLpupcounts.csv")
# convert to long
pups_long <- gather(pups_wide, key = "year", value = "count", -sitename) %>%
drop_na()
pups_spread <- spread(pups_long, key="year", value = "count")
pups_long
# join data
locations <- read_csv("NCEI-0129877_US_SSL_Sites.csv")
# join the counts and the locations
pups <- left_join(pups_long, locations, by=c("sitename" = "SITENAME")) %>%
filter(year == 2015) %>%
select(sitename,year,count,LATITUDE,LONGITUDE) %>%
rename_all(tolower)
### do some maps of counts
mylocation <- c(-180,50,-130,65)
my_map <- get_stamenmap(mylocation, zoom = 6, maptype = "watercolor")
# map and add counts
ggmap(my_map) +
geom_point(data = pups,
aes(x = longitude, y = latitude, size = count),
alpha = 0.5, shape = 21, fill = "darkgray") +
ggtitle("Steller sea lion pup counts 2015") +
xlab("Longitude") +
ylab("Latitude")
my_map <- get_map(mylocation, zoom = 6, maptype = "satellite")
ggmap(my_map) +
geom_point(data = pups,
aes(x = longitude, y = latitude, size = count),
alpha = 0.5, shape = 21, fill = "orange") +
ggtitle("Steller sea lion pup counts 2015") +
xlab("Longitude") +
ylab("Latitude")