Skip to content

Commit 3f115f1

Browse files
authored
Merge pull request #47 from elmeraa-usgs/aug24_flowtiles
August 2024 flowtiles
2 parents e6a7fb3 + d65170e commit 3f115f1

File tree

7 files changed

+50
-50
lines changed

7 files changed

+50
-50
lines changed

_targets.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ list(
3333
# Read in data from gage-flow-conditions pipeline output
3434
tar_target(
3535
dv,
36-
read_csv("https://labs.waterdata.usgs.gov/visualizations/data/flow_conditions_202407.csv", col_types = "cTnnnn")
36+
read_csv("https://labs.waterdata.usgs.gov/visualizations/data/flow_conditions_202408.csv", col_types = "cTnnnn")
3737
),
3838
tar_target(
3939
date_start,
@@ -248,16 +248,15 @@ list(
248248
tar_target(
249249
explainer_flow_national_ig_png,
250250
cowplot_national_explainer(national_plot_png = "out/flow_national_ig.png",
251-
explainer_label = "HOT TIP: Keep proportions in mind!",
252-
blue_label = "More blue = wetter conditions",
253-
orange_label = "More yellow/orange = drier conditions",
251+
blue_label = "Wetter\nconditions",
252+
orange_label = "Drier\nconditions",
254253
file_png = "out/explainer_flow_national_ig.png",
255254
width = 1080, height = 1080, font_legend, text_color,
256255
low_col = "#A84E0B", high_col = "#002D5E",
257256
low_lab = "Low\nStreamflow",
258257
high_lab = "High\nStreamflow",
259258
typ_lab = "Typical\nStreamflow",
260-
typ_lab_ypos = 0.55, typ_arr_ypos = 0.545),
259+
typ_lab_ypos = 0.62, typ_arr_ypos = 0.615),
261260
format = "file"
262261
),
263262

out/explainer_flow_national_ig.png

11.1 KB
Loading

out/flow_cartogram.png

-8.77 KB
Loading

out/flow_cartogram_ig.png

-7.08 KB
Loading

out/flow_national_ig.png

3.22 KB
Loading

out/intro_question_ig.png

-37.8 KB
Loading

src/explainer_prep.R

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#' @description Cowplot national data image with explainer annotations
2-
#' @param explainer_label top annotation for how to read the plot
32
#' @param file_png file path for final png
43
#' @param width width of final png
54
#' @param height height of final png
65
#' @param font_legend font used for legend text
76
#' @param text_color color used for viz text
87
#' @param blue_label label for wet condition interpretation tip
98
#' @param orange_label label for dry condition interpretation tip
10-
cowplot_national_explainer <- function(explainer_label, file_png, national_plot_png,
9+
cowplot_national_explainer <- function(file_png, national_plot_png,
1110
width, height, font_legend, text_color, blue_label, orange_label,
1211
low_col, high_col, low_lab, high_lab, typ_lab, typ_lab_ypos, typ_arr_ypos){
1312
# typ_lab_ypos = 0.5, typ_arr_ypos = 0.495
@@ -20,6 +19,24 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_
2019
)
2120

2221
#arrows
22+
(dry_arrow <- ggplot() +
23+
theme_void() +
24+
# add arrow using `geom_curve()`
25+
geom_curve(aes(x = -13, y = 3,
26+
xend = -11, yend = 2),
27+
arrow = grid::arrow(length = unit(0.2, 'lines')),
28+
curvature = 0.3, angle = 80, ncp = 10,
29+
color = low_col, linewidth = 0.2))
30+
31+
(wet_arrow <- ggplot() +
32+
theme_void() +
33+
# add arrow using `geom_curve()`
34+
geom_curve(aes(x = 13, y = 3,
35+
xend = 11, yend = 2),
36+
arrow = grid::arrow(length = unit(0.2, 'lines')),
37+
curvature = -0.3, angle = 80, ncp = 10,
38+
color = high_col, linewidth = 0.2))
39+
2340
(normal_range_arrow <- ggplot() +
2441
theme_void()+
2542
# add arrow using `geom_curve()`
@@ -57,56 +74,58 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_
5774
height = 1, width = 1,
5875
hjust = 0, vjust = 1) +
5976
draw_image(og_plot_png,
60-
x = 0, y = 0,
77+
x = 0.01, y = 0,
6178
width = 1,
6279
hjust = 0, vjust = 0,
63-
halign = 0, valign = 0)+
64-
draw_label(explainer_label,
65-
x = 0.5, y = 0.96,
66-
size = 5.5,
67-
hjust = 0, vjust = 1,
68-
fontfamily = font_legend,
69-
color = "#000000")+
80+
halign = 0, valign = 0) +
7081
draw_label(blue_label,
71-
x = 0.5, y = 0.91,
82+
x = 0.9, y = 0.26,
7283
size = 5.5,
73-
hjust = 0, vjust = 1,
84+
hjust = 0.5, vjust = 1,
7485
fontfamily = font_legend,
75-
color = high_col)+
86+
color = high_col) +
87+
draw_plot(wet_arrow, # for wet conditions arrow
88+
x = 0.85, y = 0.17,
89+
height = 0.05, width = 0.06,
90+
hjust = 0, vjust = 0.5) +
7691
draw_label(orange_label,
77-
x = 0.5, y = 0.88,
92+
x = 0.09, y = 0.26,
7893
size = 5.5,
79-
hjust = 0, vjust = 1,
94+
hjust = 0.5, vjust = 1,
8095
fontfamily = font_legend,
81-
color = low_col)+
96+
color = low_col) +
97+
draw_plot(dry_arrow, # for dry conditions arrow
98+
x = 0.095, y = 0.17,
99+
height = 0.05, width = 0.06,
100+
hjust = 0, vjust = 0.5) +
82101
draw_label(low_lab,
83-
x = 0.84, y = 0.355,
102+
x = 0.86, y = 0.355,
84103
size = 5.5,
85104
hjust = 0.5, vjust = 1,
86105
fontfamily = font_legend,
87106
color = low_col) +
88107
draw_label(high_lab,
89-
x = 0.84, y = 0.76,
108+
x = 0.86, y = 0.76,
90109
size = 5.5,
91110
hjust = 0.5, vjust = 1,
92111
fontfamily = font_legend,
93112
color = high_col) +
94113
draw_label(typ_lab,
95-
x = 0.855, y = typ_lab_ypos,
114+
x = 0.875, y = typ_lab_ypos,
96115
size = 5.5,
97116
hjust = 0.5, vjust = 1,
98117
fontfamily = font_legend,
99118
color = text_color) +
100119
draw_plot(high_range_arrow, # for high streamflow
101-
x = 0.755, y = 0.755,
120+
x = 0.77, y = 0.755,
102121
height = 0.035, width = 0.05,
103-
hjust = 0, vjust = 0.5)+
122+
hjust = 0, vjust = 0.5) +
104123
draw_plot(normal_range_arrow, # for typical streamflow
105-
x = 0.755, y = typ_arr_ypos,
124+
x = 0.77, y = typ_arr_ypos,
106125
height = 0.035, width = 0.05,
107-
hjust = 0, vjust = 0.5)+
126+
hjust = 0, vjust = 0.5) +
108127
draw_plot(low_range_arrow, # for low streamflow
109-
x = 0.755, y = 0.35,
128+
x = 0.77, y = 0.35,
110129
height = 0.035, width = 0.055,
111130
hjust = 0, vjust = 0.5)
112131

@@ -144,13 +163,8 @@ intro_background <- function(national_data, percentile_bin, pal){
144163
intro_image <- function(plot_nat_clean, date_start, font_legend, width, height, file_png){
145164

146165
plot_month <- lubridate::month(date_start, label = TRUE, abbr = FALSE)
147-
plot_year <- lubridate::year(date_start)
148-
149166
plot_margin <- 0.025
150167

151-
title_flow_dark <- magick::image_read('in/streamflow.png') |> magick::image_scale('800x') %>%
152-
magick::image_colorize(100, "#222222") |> magick::image_scale('800x')
153-
154168
# background
155169
canvas <- grid::rectGrob(
156170
x = 0, y = 0,
@@ -168,23 +182,10 @@ intro_image <- function(plot_nat_clean, date_start, font_legend, width, height,
168182
# national-level plot
169183
draw_plot(plot_nat_clean,
170184
x = -0.055, y = -0.09,
171-
height = 1.18, width = 1.18)+
172-
# draw title
173-
draw_label(sprintf('%s %s', plot_month, plot_year),
174-
x = plot_margin*2, y = 1-plot_margin*1.2,
175-
size = 16,
176-
hjust = 0, vjust = 1,
177-
fontfamily = font_legend,
178-
color = "#222222",
179-
lineheight = 1) +
180-
# stylized streamflow title
181-
draw_image(title_flow_dark ,
182-
x = plot_margin*2, y = 1-(1.5*plot_margin),
183-
height = 0.16, width = 0.74,
184-
hjust = 0, vjust = 1) +
185-
draw_label(sprintf("How did %s's\nstreamflow\ncompare to the\npast?", plot_month),
185+
height = 1.18, width = 1.18) +
186+
draw_label(sprintf("A look at %s's\nstreamflow across\nthe U.S.", plot_month),
186187
x = 0.05, y = 0.5,
187-
size = 26,
188+
size = 22,
188189
hjust = 0, vjust = 0.5,
189190
fontfamily = font_legend,
190191
color = "#222222")

0 commit comments

Comments
 (0)