Skip to content

Commit

Permalink
Merge pull request #47 from elmeraa-usgs/aug24_flowtiles
Browse files Browse the repository at this point in the history
August 2024 flowtiles
  • Loading branch information
elmeraa-usgs authored Sep 3, 2024
2 parents e6a7fb3 + d65170e commit 3f115f1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
9 changes: 4 additions & 5 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ list(
# Read in data from gage-flow-conditions pipeline output
tar_target(
dv,
read_csv("https://labs.waterdata.usgs.gov/visualizations/data/flow_conditions_202407.csv", col_types = "cTnnnn")
read_csv("https://labs.waterdata.usgs.gov/visualizations/data/flow_conditions_202408.csv", col_types = "cTnnnn")
),
tar_target(
date_start,
Expand Down Expand Up @@ -248,16 +248,15 @@ list(
tar_target(
explainer_flow_national_ig_png,
cowplot_national_explainer(national_plot_png = "out/flow_national_ig.png",
explainer_label = "HOT TIP: Keep proportions in mind!",
blue_label = "More blue = wetter conditions",
orange_label = "More yellow/orange = drier conditions",
blue_label = "Wetter\nconditions",
orange_label = "Drier\nconditions",
file_png = "out/explainer_flow_national_ig.png",
width = 1080, height = 1080, font_legend, text_color,
low_col = "#A84E0B", high_col = "#002D5E",
low_lab = "Low\nStreamflow",
high_lab = "High\nStreamflow",
typ_lab = "Typical\nStreamflow",
typ_lab_ypos = 0.55, typ_arr_ypos = 0.545),
typ_lab_ypos = 0.62, typ_arr_ypos = 0.615),
format = "file"
),

Expand Down
Binary file modified out/explainer_flow_national_ig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified out/flow_cartogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified out/flow_cartogram_ig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified out/flow_national_ig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified out/intro_question_ig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 46 additions & 45 deletions src/explainer_prep.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#' @description Cowplot national data image with explainer annotations
#' @param explainer_label top annotation for how to read the plot
#' @param file_png file path for final png
#' @param width width of final png
#' @param height height of final png
#' @param font_legend font used for legend text
#' @param text_color color used for viz text
#' @param blue_label label for wet condition interpretation tip
#' @param orange_label label for dry condition interpretation tip
cowplot_national_explainer <- function(explainer_label, file_png, national_plot_png,
cowplot_national_explainer <- function(file_png, national_plot_png,
width, height, font_legend, text_color, blue_label, orange_label,
low_col, high_col, low_lab, high_lab, typ_lab, typ_lab_ypos, typ_arr_ypos){
# typ_lab_ypos = 0.5, typ_arr_ypos = 0.495
Expand All @@ -20,6 +19,24 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_
)

#arrows
(dry_arrow <- ggplot() +
theme_void() +
# add arrow using `geom_curve()`
geom_curve(aes(x = -13, y = 3,
xend = -11, yend = 2),
arrow = grid::arrow(length = unit(0.2, 'lines')),
curvature = 0.3, angle = 80, ncp = 10,
color = low_col, linewidth = 0.2))

(wet_arrow <- ggplot() +
theme_void() +
# add arrow using `geom_curve()`
geom_curve(aes(x = 13, y = 3,
xend = 11, yend = 2),
arrow = grid::arrow(length = unit(0.2, 'lines')),
curvature = -0.3, angle = 80, ncp = 10,
color = high_col, linewidth = 0.2))

(normal_range_arrow <- ggplot() +
theme_void()+
# add arrow using `geom_curve()`
Expand Down Expand Up @@ -57,56 +74,58 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_
height = 1, width = 1,
hjust = 0, vjust = 1) +
draw_image(og_plot_png,
x = 0, y = 0,
x = 0.01, y = 0,
width = 1,
hjust = 0, vjust = 0,
halign = 0, valign = 0)+
draw_label(explainer_label,
x = 0.5, y = 0.96,
size = 5.5,
hjust = 0, vjust = 1,
fontfamily = font_legend,
color = "#000000")+
halign = 0, valign = 0) +
draw_label(blue_label,
x = 0.5, y = 0.91,
x = 0.9, y = 0.26,
size = 5.5,
hjust = 0, vjust = 1,
hjust = 0.5, vjust = 1,
fontfamily = font_legend,
color = high_col)+
color = high_col) +
draw_plot(wet_arrow, # for wet conditions arrow
x = 0.85, y = 0.17,
height = 0.05, width = 0.06,
hjust = 0, vjust = 0.5) +
draw_label(orange_label,
x = 0.5, y = 0.88,
x = 0.09, y = 0.26,
size = 5.5,
hjust = 0, vjust = 1,
hjust = 0.5, vjust = 1,
fontfamily = font_legend,
color = low_col)+
color = low_col) +
draw_plot(dry_arrow, # for dry conditions arrow
x = 0.095, y = 0.17,
height = 0.05, width = 0.06,
hjust = 0, vjust = 0.5) +
draw_label(low_lab,
x = 0.84, y = 0.355,
x = 0.86, y = 0.355,
size = 5.5,
hjust = 0.5, vjust = 1,
fontfamily = font_legend,
color = low_col) +
draw_label(high_lab,
x = 0.84, y = 0.76,
x = 0.86, y = 0.76,
size = 5.5,
hjust = 0.5, vjust = 1,
fontfamily = font_legend,
color = high_col) +
draw_label(typ_lab,
x = 0.855, y = typ_lab_ypos,
x = 0.875, y = typ_lab_ypos,
size = 5.5,
hjust = 0.5, vjust = 1,
fontfamily = font_legend,
color = text_color) +
draw_plot(high_range_arrow, # for high streamflow
x = 0.755, y = 0.755,
x = 0.77, y = 0.755,
height = 0.035, width = 0.05,
hjust = 0, vjust = 0.5)+
hjust = 0, vjust = 0.5) +
draw_plot(normal_range_arrow, # for typical streamflow
x = 0.755, y = typ_arr_ypos,
x = 0.77, y = typ_arr_ypos,
height = 0.035, width = 0.05,
hjust = 0, vjust = 0.5)+
hjust = 0, vjust = 0.5) +
draw_plot(low_range_arrow, # for low streamflow
x = 0.755, y = 0.35,
x = 0.77, y = 0.35,
height = 0.035, width = 0.055,
hjust = 0, vjust = 0.5)

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

plot_month <- lubridate::month(date_start, label = TRUE, abbr = FALSE)
plot_year <- lubridate::year(date_start)

plot_margin <- 0.025

title_flow_dark <- magick::image_read('in/streamflow.png') |> magick::image_scale('800x') %>%
magick::image_colorize(100, "#222222") |> magick::image_scale('800x')

# background
canvas <- grid::rectGrob(
x = 0, y = 0,
Expand All @@ -168,23 +182,10 @@ intro_image <- function(plot_nat_clean, date_start, font_legend, width, height,
# national-level plot
draw_plot(plot_nat_clean,
x = -0.055, y = -0.09,
height = 1.18, width = 1.18)+
# draw title
draw_label(sprintf('%s %s', plot_month, plot_year),
x = plot_margin*2, y = 1-plot_margin*1.2,
size = 16,
hjust = 0, vjust = 1,
fontfamily = font_legend,
color = "#222222",
lineheight = 1) +
# stylized streamflow title
draw_image(title_flow_dark ,
x = plot_margin*2, y = 1-(1.5*plot_margin),
height = 0.16, width = 0.74,
hjust = 0, vjust = 1) +
draw_label(sprintf("How did %s's\nstreamflow\ncompare to the\npast?", plot_month),
height = 1.18, width = 1.18) +
draw_label(sprintf("A look at %s's\nstreamflow across\nthe U.S.", plot_month),
x = 0.05, y = 0.5,
size = 26,
size = 22,
hjust = 0, vjust = 0.5,
fontfamily = font_legend,
color = "#222222")
Expand Down

0 comments on commit 3f115f1

Please sign in to comment.