-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlogo.R
97 lines (89 loc) · 2.22 KB
/
logo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
library(sf)
library(tidyverse)
library(rnaturalearth)
library(hexSticker)
library(here)
set.seed(3141592)
ne_dir <- tempdir()
ne_file <- file.path(ne_dir, "ne_110m_land.zip")
download.file(
url = "https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_land.zip",
destfile = ne_file, quiet = TRUE
)
unzip(ne_file, exdir = ne_dir)
map <- rnaturalearth::ne_load(
scale = "small", type = "land", category = "physical",
returnclass = "sf", destdir = ne_dir
) %>% st_make_valid
st_agr(map) <- "constant"
map <- st_crop(
map,
st_bbox(c(xmin = -28, xmax = 80, ymin = -49, ymax = 70),
crs = 4326)
)
points_df <- tribble(
~lon, ~lat, ~id,
-5, 20, 1,
10, 10, 2,
20, 25, 3,
20, -4, 4,
25, 5, 5,
30, 18, 5.1,
35, 10, 6,
35, -4, 7,
40, 37, 8,
25, 40, 9,
12, 48, 10,
27, 53, 10.1,
45, 43, 11,
62, 35, 12,
45, 30, 13,
55, 20, 14,
45, 17, 15
) %>% mutate(id = factor(id))
edges_df <- tribble(
~from, ~to,
1, 2,
1, 3,
2, 4,
2, 5,
3, 5.1,
3, 8,
6, 15,
5, 6,
8, 9,
9, 10,
9, 10.1,
8, 11,
15, 13,
13, 12,
15, 14,
5, 7
) %>% mutate(
x = sapply(from, function(i) filter(points_df, id == i)$lon),
y = sapply(from, function(i) filter(points_df, id == i)$lat),
xend = sapply(to, function(i) filter(points_df, id == i)$lon),
yend = sapply(to, function(i) filter(points_df, id == i)$lat),
from = factor(from), to = factor(to)
)
p <- ggplot() +
geom_sf(data = map, color = NA) +
# geom_label(data = points_df, aes(lon, lat, label = id)) +
geom_segment(data = edges_df, aes(x = x, y = y, xend = xend, yend = yend, color = from)) +
geom_point(data = points_df, aes(lon, lat, color = id), size = 1.5) +
guides(color = "none", fill = "none") +
theme_void() +
theme_transparent() +
geom_rect(aes(xmin = -30, xmax = 80, ymin = -22, ymax = -7), fill = "white",
color = "black")
sticker(
p, package = "slendr",
p_size = 21, p_y = 0.35, p_color = "black",
h_color = "black", h_fill = "#0077be",
s_y = 0.9, s_x = 0.99, s_width = 2.7, s_height = 2.7,
white_around_sticker = TRUE,
filename = file.path(".", "logo.png")
)
usethis::use_logo("logo.png")
system("convert man/figures/logo.png -define png:include-chunk=none man/figures/logo.png")
unlink("logo.png")