icon_map <- c(
"Warm.Dry" = "sun",
"Warm.Wet" = "cloud-rain",
"Cold.Dry" = "wind",
"Cold.Wet" = "snowflake"
)
df_fc <- data.frame(
day = 1:8,
temp = c(18, 20, 15, 12, 10, 9, 13, 17),
temp_cat = c("Warm", "Warm", "Warm", "Cold", "Cold", "Cold", "Cold", "Warm"),
precip = c("Dry", "Dry", "Wet", "Dry", "Wet", "Wet", "Dry", "Wet"),
alert = c("Advisory", "Advisory", "Advisory", "Warning",
"Warning", "Warning", "Advisory", "Advisory"),
avg = c(14, 14, 13.5, 13, 13, 13, 13.5, 14),
stringsAsFactors = FALSE
)
df_fc$icon <- icon_map[paste(df_fc$temp_cat, df_fc$precip, sep = ".")]
# the warmest day in the outlook is flagged as the pick
warmest <- df_fc[which.max(df_fc$temp), ]
p_main <- ggplot(df_fc, aes(x = day, y = temp)) +
geom_ribbon(aes(ymin = avg - 4, ymax = avg + 4), fill = "grey88") +
geom_line(aes(y = avg), colour = "grey35", linewidth = 0.7) +
# a soft ring highlights the warmest day so the * is unambiguous
geom_point(data = warmest, shape = 21, size = 10, colour = "#D9A441",
fill = NA, stroke = 1.3) +
geom_icon_point(
aes(icon = icon, colour = alert),
size = 3, dpi = 150, legend_icons = FALSE, show.legend = FALSE
) +
annotate("text", x = warmest$day + 0.35, y = warmest$temp + 1.3, label = "*",
size = 6, fontface = "bold") +
scale_colour_manual(values = alert_col, guide = "none") +
scale_x_continuous("Forecast day", breaks = 1:8) +
scale_y_continuous("High temperature (C)", limits = c(4, 22), breaks = seq(4, 20, 4)) +
labs(
title = "8-day temperature outlook",
subtitle = "Marker shape = temperature and precipitation; colour = alert level; the * is the warmest day"
) +
theme_classic(base_size = 13) +
theme(
axis.line.x = element_blank(),
plot.subtitle = element_text(size = 9.5, colour = "grey30"),
panel.grid.major.y = element_line(colour = "grey93", linewidth = 0.3)
)
p_legend <- legend_canvas(
df_legend,
grid_title = "Temp and precip",
group_section = "alert", group_title = "Alert", group_width = 0.85, group_gap = 0.18,
symbol_section = "mark", symbol_right_gap = 0.75, symbol_key_width = 0.45,
col_spacing = 0.95, row_spacing = 1.2, label_gap = 0.12,
marker_size = 5, label_size = 3.6, dpi = 150,
x_margin = c(1.6, 1.6)
)
p_main + legend_strip(p_legend, height = 1.4)