-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-physical.R
125 lines (116 loc) · 3.19 KB
/
07-physical.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Load packages -----------------------------------------------------------
library(tidyverse)
library(lubridate)
library(countrycode)
library(ggridges)
library(ggfx)
library(gganimate)
# Import data -------------------------------------------------------------
prayers_time <-
read_csv("data/prayers_time.csv")
# Preprocess data to plot -------------------------------------------------
to_plot <-
prayers_time %>%
filter(country != "Svalbard and Jan Mayen") %>%
anti_join(
filter(., maghrib - fajr < dhours(5))
) %>%
mutate(
continent = countryname(country, destination = "continent"),
duration = (as.numeric(maghrib - fajr)),
continent = fct_reorder(continent, duration)
) %>%
drop_na()
# Create plot -------------------------------------------------------------
anim <-
to_plot %>%
ggplot(aes(duration, continent)) +
as_reference(
geom_text(
data = to_plot %>%
summarise(
x_pos = 9,
y_pos = unique(continent),
continent = toupper(y_pos)
),
aes(x_pos, y_pos, label = continent),
inherit.aes = FALSE,
hjust = 0,
vjust = 0,
family = "Assistant",
fontface = "bold",
colour = "#93E5AB",
size = 13
),
id = "text"
) +
with_blend(
geom_density_ridges(
rel_min_height = 0.001,
fill = "#E3DBDB",
colour = "#034C3C"
),
bg_layer = "text",
blend_type = "xor"
) +
labs(
caption = "{format(as.Date(frame_time), format = 'DAY %d')}"
) +
annotate(
geom = "text",
x = 21,
y = 1.9,
label = "Fasting duration\nduring Ramadhan 2021",
family = "Titillium Web",
colour = "#E3DBDB",
size = 5,
hjust = 1,
lineheight = 0.9
) +
annotate(
geom = "text",
x = 9,
y = 1,
label = "Data source: aladhan.com | Visualized by Muhammad Aswan Syahputra",
family = "Titillium Web",
colour = "#E3DBDB",
size = 3,
hjust = 0,
vjust = 5
) +
scale_y_discrete(expand = c(0, 0.05)) +
scale_x_continuous(breaks = c(12, 15, 18), labels = function(x) paste(x, "hours"), position = "top", expand = c(0.05, 0)) +
theme_minimal(
base_family = "Assistant"
) +
theme(
plot.background = element_rect(fill = "#034C3C", colour = NA),
panel.background = element_rect(fill = "#034C3C", colour = NA),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.x = element_line(linetype = "dotted", size = 0.1, colour = "#C5E0D8"),
panel.grid.major.y = element_blank(),
plot.caption.position = "plot",
plot.caption = element_text(hjust = 0.95, vjust = 5.25, face = "bold", colour = "#FCD0A1", size = rel(4.25)),
axis.text.x = element_text(colour = "#C5E0D8"),
axis.text.y = element_blank(),
axis.title = element_blank(),
plot.margin = margin(25, 5, 0, 5)
) +
coord_cartesian(clip = "off") +
transition_time(hijri_date) +
ease_aes()
# Save animation ----------------------------------------------------------
anim_save(
"outfile/07-physical.gif",
animation = anim,
duration = 15,
fps = 30,
width = 8,
height = 5,
units = "in",
device = "png",
type = "cairo-png",
res = 150,
renderer = gifski_renderer(loop = TRUE)
)