-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathinset.R
52 lines (39 loc) · 1.59 KB
/
inset.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
# inset map -- need to comment this code...
header <- readRDS("R/portraits/fifth_pillars/header.rds")
world <- rnaturalearth::ne_countries(scale = "small", returnclass = "sf")
coords <- header$coords
prj <- glue("+proj=ortho +lat_0={coords[2]} +lon_0={coords[1]} +x_0=0 +y_0=0 +a=6375000 +b=6375000 +units=m +no_defs")
water <- st_sfc(st_point(c(0, 0)), crs = prj) %>%
st_buffer(., 6371000) %>%
st_transform(crs = 4326)
circle_coords <- st_coordinates(water)[, c(1,2)]
circle_coords <- circle_coords[order(circle_coords[, 1]),]
circle_coords <- circle_coords[!duplicated(circle_coords),]
rectangle <- list(rbind(circle_coords,
c(X = 180, circle_coords[nrow(circle_coords), 'Y']),
c(X = 180, Y = 90),
c(X = -180, Y = 90),
c(X = -180, circle_coords[1, 'Y']),
circle_coords[1, c('X','Y')])) %>%
st_polygon() %>% st_sfc(crs = 4326)
rectangle %>%
ggplot()+
geom_sf(data = world) +
geom_sf(color = "red", fill = alpha("red", .5))
sf::sf_use_s2(FALSE)
w <- st_intersection(world, rectangle)
w %>%
ggplot() +
geom_sf()
spot <- tibble(x = coords[1], y = coords[2]) |>
st_as_sf(coords = c("x", "y"), crs = 4326)
colors <- header$colors
water_color <- colors[7]
text_color <- colors[1]
loc_plot <- ggplot(data = w) +
geom_sf(data = water, color = NA, fill = alpha("white", .75)) +
geom_sf(fill = "red", size = .1, color = "white") +
coord_sf(crs = prj) +
theme_void()
loc_plot
ggsave(loc_plot, filename = glue("images/{header$map}/{header$pal}_inset.png"), w = 4*1.5, h = 3*1.5)