-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_plot_site_locations.R
executable file
·50 lines (41 loc) · 1.79 KB
/
1_plot_site_locations.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
#!/usr/bin/env Rscript
library(tidyverse)
library(maps)
library(mapproj)
dir.create("plots", showWarnings=FALSE)
coords <- read_csv("data/site_coordinates.csv") %>%
group_by(Community_ID) %>%
summarise(Latitude = mean(Latitude),
Longitude = mean(Longitude))
data_map <- read_csv("data/combined_long_data.csv") %>%
rename(region = Country_full,
community = Community_ID,
`Site type` = Urb_rural) %>%
mutate(region = if_else(region == "Congo", "Republic of Congo", region),
`Site type` = str_to_title(`Site type`)) %>%
group_by(region, community, `Site type`) %>%
summarise(Participants = n_distinct(Participant_ID))
data_map <- left_join(data_map, coords, by=join_by(community==Community_ID))
world <- map_data("world")
selWorld <- left_join(world, select(data_map, region, Participants), by = "region")%>%
filter(region != "Antarctica")%>%
mutate(fill = ifelse(is.na(Participants), "out", "in")) %>%
filter(! long > 180)
world_map <- selWorld %>%
rename(Latitude = lat,
Longitude = long) %>%
ggplot(aes(x = Longitude, y = Latitude, group = group)) +
coord_map(projection="gall", lat0=0) +
geom_polygon(aes(fill = fill), col = "white", linewidth = 0.10, show.legend=FALSE) +
scale_fill_manual(values = c("#3F7979", "#B7D6D6")) +
geom_point(data = data_map, aes(x = Longitude, y = Latitude, shape=`Site type`), inherit.aes = F, stroke = 0.33) +
scale_shape_manual(values = c(1, 2)) +
scale_size(range=c(0.50, 2.0)) +
theme_light() +
theme(axis.title = element_text(size=6),
axis.text = element_text(size=4),
legend.title = element_text(size=6),
legend.text = element_text(size=4),
strip.text.x = element_text(margin = margin(b = 1, t=1))
)
ggsave("plots/world_map.png", plot=world_map, dpi=600, width=180, height=90, units="mm")