diff --git a/_targets.R b/_targets.R index b76f47d..501db96 100644 --- a/_targets.R +++ b/_targets.R @@ -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, @@ -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" ), diff --git a/out/explainer_flow_national_ig.png b/out/explainer_flow_national_ig.png index 7a58ed7..50cabcf 100644 Binary files a/out/explainer_flow_national_ig.png and b/out/explainer_flow_national_ig.png differ diff --git a/out/flow_cartogram.png b/out/flow_cartogram.png index 96c5ce1..bc920de 100644 Binary files a/out/flow_cartogram.png and b/out/flow_cartogram.png differ diff --git a/out/flow_cartogram_ig.png b/out/flow_cartogram_ig.png index ec5bfc2..f12d1a1 100644 Binary files a/out/flow_cartogram_ig.png and b/out/flow_cartogram_ig.png differ diff --git a/out/flow_national_ig.png b/out/flow_national_ig.png index 0259c61..d03f804 100644 Binary files a/out/flow_national_ig.png and b/out/flow_national_ig.png differ diff --git a/out/intro_question_ig.png b/out/intro_question_ig.png index dd14bdd..2fe238e 100644 Binary files a/out/intro_question_ig.png and b/out/intro_question_ig.png differ diff --git a/src/explainer_prep.R b/src/explainer_prep.R index 86f78d6..3dc200e 100644 --- a/src/explainer_prep.R +++ b/src/explainer_prep.R @@ -1,5 +1,4 @@ #' @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 @@ -7,7 +6,7 @@ #' @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 @@ -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()` @@ -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) @@ -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, @@ -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")