@@ -131,7 +131,8 @@ df_ign <- df_ign |>
131131 `Depth(km)` >= 28 ~ "Deep (>28km)",
132132 `Depth(km)` >= 18 ~ "Interchange (18km>x>28km)",
133133 TRUE ~ "Shallow (< 18km)"
134- ))
134+ )
135+ )
135136df_ign
136137```
137138
@@ -140,14 +141,15 @@ df_ign
140141#| label: epochs
141142cut_times <- ymd_hms(c("2021-09-11", "2021-09-19 14:13:00", "2021-10-01", "2021-12-01", "2021-12-31", "2022-01-01"), truncated = 3)
142143epochs <- tibble(
143- start = cut_times[-length(cut_times)],
144- end = cut_times[-1],
144+ start = cut_times[-length(cut_times)],
145+ end = cut_times[-1],
145146 label = c("pre", "early", "phase1", "phase2", "phase3"),
146- text = c('Pre\nEruptive\nSwarm',
147- 'Early Eruptive\nPhase',
148- 'Main Eruptive Phase\n(sustained gas and lava ejection)',
149- 'Final Eruptive Phase\n(reducing gas and lava ejection)',
150- NA
147+ text = c(
148+ "Pre\nEruptive\nSwarm",
149+ "Early Eruptive\nPhase",
150+ "Main Eruptive Phase\n(sustained gas and lava ejection)",
151+ "Final Eruptive Phase\n(reducing gas and lava ejection)",
152+ NA
151153 )
152154)
153155```
@@ -156,19 +158,22 @@ epochs <- tibble(
156158```{r}
157159#| label: "erupt-data"
158160mag_breaks <- c(0, 1, 2, 3, 4, 6)
159- mag_labels <- c("0 < M <= 1","1 < M <= 2","2 < M <= 3","3 < M <= 4","M > 4")
161+ mag_labels <- c("0 < M <= 1", "1 < M <= 2", "2 < M <= 3", "3 < M <= 4", "M > 4")
160162df_erupt <- df_ign |>
161163 filter(Date < as.Date("2022-01-01") & Date > as.Date("2021-09-11")) |>
162- mutate(Magnitude_categories = cut(Magnitude,
163- breaks = mag_breaks, labels = mag_labels, right = FALSE))
164+ mutate(Magnitude_categories = cut(Magnitude,
165+ breaks = mag_breaks, labels = mag_labels, right = FALSE
166+ ))
164167```
165168
166169
167170```{r}
168171#| label: colors
169- colors <- c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a",
170- "#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2",
171- "#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5")
172+ colors <- c(
173+ "#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a",
174+ "#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2",
175+ "#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5"
176+ )
172177```
173178
174179
@@ -178,41 +183,55 @@ colors <- c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a",
178183#| fig-width: 24
179184#| fig-height: 12
180185eruption <- ymd_hms("2021-09-19 14:13:00")
181- date_axis_breaks <- as.Date("2021-10-15") + months(rep(0:2, each = 2)) -
182- days(rep(c(14, 0), times = 3))
186+ date_axis_breaks <- as.Date("2021-10-15") + months(rep(0:2, each = 2)) -
187+ days(rep(c(14, 0), times = 3))
183188date_axis_breaks <- c(eruption, date_axis_breaks[-1])
184189
185190# Custom Magnitude Scale transform
186191trans_mag <- scales::trans_new(
187192 name = "Magnitude transformation",
188- transform = \(x) 3* 2^(1.3* x),
189- inverse = \(x) (1/ 1.3) * log2(x/ 3)
193+ transform = \(x) 3 * 2^(1.3 * x),
194+ inverse = \(x) (1 / 1.3) * log2(x / 3)
190195)
191196
192-
197+
193198df_erupt |>
194- arrange(Magnitude) |>
195- ggplot(aes(DateTime, `Depth(km)`)) +
196- geom_point(aes(fill = Magnitude_categories, size = Magnitude,
197- alpha = Magnitude_categories), shape = 21, color = "black") +
199+ arrange(Magnitude) |>
200+ ggplot(aes(DateTime, `Depth(km)`)) +
201+ geom_point(aes(
202+ fill = Magnitude_categories, size = Magnitude,
203+ alpha = Magnitude_categories
204+ ), shape = 21, color = "black") +
198205 geom_vline(xintercept = eruption, color = colors[7]) +
199- annotate("text", x = eruption, y = 20, label = "ERUPTION",
200- color = colors[7], angle = 90, hjust = 1, vjust = -0.2, size = 6) +
201- annotate("rect", xmin = epochs$start, xmax = epochs$end,
202- ymin = -Inf, ymax = Inf, fill = colors[c(1, 3, 5, 7, 7)], alpha = 0.1) +
203- annotate("text", x = epochs$start + 0.5*(epochs$end - epochs$start), y = -4,
204- label = epochs$text, color = colors[c(1, 3, 5, 7, NA)], size = 7) +
205- scale_y_continuous("Depth (km)", trans = scales::reverse_trans(),
206- breaks = seq(0, 40, 10), limits = c( 45, -5), sec.axis = dup_axis()) +
207- scale_x_datetime("Eruption Timeline", expand = c(0, 0),
208- date_labels = "%Y-%m-%d", breaks = date_axis_breaks) +
206+ annotate("text",
207+ x = eruption, y = 20, label = "ERUPTION",
208+ color = colors[7], angle = 90, hjust = 1, vjust = -0.2, size = 6
209+ ) +
210+ annotate("rect",
211+ xmin = epochs$start, xmax = epochs$end,
212+ ymin = -Inf, ymax = Inf, fill = colors[c(1, 3, 5, 7, 7)], alpha = 0.1
213+ ) +
214+ annotate("text",
215+ x = epochs$start + 0.5 * (epochs$end - epochs$start), y = -4,
216+ label = epochs$text, color = colors[c(1, 3, 5, 7, NA)], size = 7
217+ ) +
218+ scale_y_continuous("Depth (km)",
219+ trans = scales::reverse_trans(),
220+ breaks = seq(0, 40, 10), limits = c(45, -5), sec.axis = dup_axis()
221+ ) +
222+ scale_x_datetime("Eruption Timeline",
223+ expand = c(0, 0),
224+ date_labels = "%Y-%m-%d", breaks = date_axis_breaks
225+ ) +
209226 scale_fill_manual("Event Magnitude (M)", values = colors[c(13, 17, 5, 3, 7)]) +
210227 scale_alpha_manual("Event Magnitude (M)", values = c(0.3, 0.4, 0.5, 0.6, 0.8)) +
211- scale_size("Event Magnitude (M)", breaks = 1:5, labels = mag_labels,
212- trans = trans_mag) +
213- theme_bw(base_size = 20, base_family = "Helvetica") +
228+ scale_size("Event Magnitude (M)",
229+ breaks = 1:5, labels = mag_labels,
230+ trans = trans_mag
231+ ) +
232+ theme_bw(base_size = 20, base_family = "Helvetica") +
214233 theme(
215- legend.position = c(0.01, 0.01),
234+ legend.position = c(0.01, 0.01),
216235 legend.justification = c("left", "bottom"),
217236 panel.grid.major.x = element_blank(),
218237 panel.grid.minor.x = element_blank(),
@@ -233,19 +252,20 @@ df_erupt |>
233252#| fig-width: 8
234253blue <- "#336699"
235254
236- p <- df_ign |>
255+ p <- df_ign |>
237256 ggplot(aes(Magnitude, `Depth(km)`)) +
238257 geom_point(alpha = 0.6, color = blue) +
239- geom_density2d(color = blue, n = 100, h = c(1, 8), bins = 20) +
258+ geom_density2d(color = blue, n = 100, h = c(1, 8), bins = 20) +
240259 scale_y_continuous(trans = "reverse") +
241- coord_fixed(ratio = 1/ 8) +
242- labs(title = "Cumulative Events 01-01-2017 to 01-01-2022") +
260+ coord_fixed(ratio = 1 / 8) +
261+ labs(title = "Cumulative Events 01-01-2017 to 01-01-2022") +
243262 theme_bw() +
244263 theme(
245- plot.title = element_text(hjust = 0.5, margin = margin(t = 20, b = 20)))
246-
264+ plot.title = element_text(hjust = 0.5, margin = margin(t = 20, b = 20))
265+ )
266+
247267
248- ggMarginal(p, type = "histogram", bins = 20, fill = blue, color = "white")
268+ ggMarginal(p, type = "histogram", bins = 20, fill = blue, color = "white")
249269```
250270
251271# Results
0 commit comments