-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhex_sticker.R
84 lines (65 loc) · 2.62 KB
/
hex_sticker.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
# hex_sticker.R
# The purpose of this script is to create hex stickers!
# Robert Schlegel
# May 3rd, 2018
# Load libraries ----------------------------------------------------------
library(hexSticker)
library(heatwaveR)
library(tidyverse)
library(showtext)
# library(extrafont)
# font_import() # Shouldn't need to be run more than once
# Create logo -------------------------------------------------------------
# The event line figure
ts_dat <- ts2clm(sst_WA, climatologyPeriod = c("1983-01-01", "2012-12-31"))
res <- detect_event(ts_dat)
el <- event_line(res, spread = 200, metric = "intensity_cumulative",
start_date = "2010-10-01", end_date = "2011-08-30")
el
# The geom_flame figure
mhw <- res$clim
mhw <- mhw[10627:10690,]
gf <- ggplot(mhw, aes(x = t, y = temp)) +
geom_flame(aes(y2 = thresh)) +
theme_void()
gf
gf2 <- ggplot(mhw, aes(x = t, y = temp)) +
geom_flame(aes(y2 = thresh), fill = "red") +
theme_void()
gf2
# The category flame
clim_cat <- mhw %>%
dplyr::mutate(diff = thresh - seas,
thresh_2x = thresh + diff,
thresh_3x = thresh_2x + diff,
thresh_4x = thresh_3x + diff)
# Set category fill colours
fillColCat <- c(
"Moderate" = "#ffc866",
"Strong" = "#ff6900",
"Severe" = "#9e0000",
"Extreme" = "#2d0000"
)
gf3 <- ggplot(data = clim_cat, aes(x = t, y = temp)) +
geom_flame(aes(y2 = thresh, fill = "Moderate")) +
geom_flame(aes(y2 = thresh_2x, fill = "Strong")) +
geom_flame(aes(y2 = thresh_3x, fill = "Severe")) +
geom_flame(aes(y2 = thresh_4x, fill = "Extreme")) +
scale_fill_manual(name = NULL, values = fillColCat, guide = FALSE) +
scale_x_date(date_labels = "%b %Y") +
theme_void()
gf3
# I prefer the geom_flame
# Place it on a sticker ---------------------------------------------------
# OperatorMono download location
# https://www.cufonfonts.com/font/operator-mono
# Then put the file in the ~/.fonts folder and unzip
font_add(family = "OperatorMono-MediumItalic", regular = ".fonts/OperatorMono-MediumItalic.otf")
# Create hex sticker
sticker(gf3, package = "heatwaveR", p_size = 66, s_x = 1.06, s_y = 1.1, s_width = 1.6, s_height = 1.6,
h_fill = "royalblue4", h_color = "#9e0000", p_family = "OperatorMono-MediumItalic", filename = "~/heatwaveR/logo.png",
dpi = 900)
# sticker(gf2, package = "heatwaveR", p_size = 8, s_x = 1.05, s_y = 0.8, s_width = 1.4, s_height = 1.0,
# h_fill = "navy", h_color = "white", p_family = "UbuntuMono-BI", filename = "logo.png")
# devtools::check() creates notes when there are things in the root that it doesn't expect
# This includes any .png files that are not labeled "logo.png"