From 49d19ed8c3711dfdec130663f0a7181afaf66fc6 Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Fri, 17 May 2024 14:57:43 -0400 Subject: [PATCH 1/8] add targets and src functions for explainer images --- _targets.R | 47 +++++- src/explainer_prep.R | 346 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 392 insertions(+), 1 deletion(-) create mode 100644 src/explainer_prep.R diff --git a/_targets.R b/_targets.R index ad09f74..6f6ef26 100644 --- a/_targets.R +++ b/_targets.R @@ -6,6 +6,7 @@ tar_option_set(packages = c('tidyverse', 'lubridate', 'geofacet', 'cowplot','ggf source("src/prep_data.R") source("src/plot_cartogram.R") +source("src/explainer_prep.R") # wet to dry color scale pal_wetdry <- c("#002D5E", "#0C7182", "#6CB7B0", "#A7D2D8", "#E0D796", "#AF9423", "#A84E0B") @@ -108,7 +109,7 @@ list( width = 16, height = 9, color_bknd, text_color, font_legend, source_label), format = "file" - ), + ), # Remove facet clipping and save as png tar_target( flow_cartogram_png, @@ -163,6 +164,8 @@ list( format = "file" ), + #### explainer image - will be a new target or two #### + # Flow timeseries for states - Instagram tar_target( flow_cartogram_instagram_svg, @@ -237,5 +240,47 @@ list( pattern = map(plot_cart_state_ig_story_list, state_abbr_filter), format = 'file', iteration = 'list' + ), + + #### explainer images and updated state #### + + tar_target( + explainer_pal, + c("#002D5E", "#0C7182", "#6CB7B0", "#C0C0C0", "#F0DB85", "#AF9423", "#A84E0B") + ), + + tar_target( + explainer_national_plot, + prep_and_plot_national_data(national_data = flow_national, date_start, date_end, + color_bknd, text_color, axis_text_size = 6, + axis_title_bottom_size = 10, axis_title_top_size = 12, + pal = explainer_pal) + ), + + tar_target( + explainer_restyle_legend, + restyle_legend_explainer(plot_nat = explainer_national_plot, barwidth = 12, barheight = 0.6, text_size = 6.5) + ), + + tar_target( + explainer_flow_national_ig_png, + cowplot_national_explainer(plot_nat = explainer_national_plot, date_start, + flow_label = "Streamflow percentile at USGS streamgages\nrelative to the historic record.", + source_label, legend = explainer_restyle_legend, + explainer_label = "Keep proportions in mind!\n\nMore blue = wetter conditions\nMore yellow/orange = drier conditions", + file_png = "out/explainer_flow_national_ig.png", + width = 1080, height = 1080, font_legend, text_color), + format = "file" + ), + + tar_target( + explainer_intro_background, + intro_background(national_data = flow_national, percentile_bin, pal = explainer_pal) + ), + + tar_target( + intro_question_ig_png, + intro_image(plot_nat_clean = explainer_intro_background, date_start, + font_legend, width = 1080, height = 1080, file_png = "out/intro_question_ig.png") ) ) \ No newline at end of file diff --git a/src/explainer_prep.R b/src/explainer_prep.R new file mode 100644 index 0000000..7f9e090 --- /dev/null +++ b/src/explainer_prep.R @@ -0,0 +1,346 @@ +#' @description Prep and plot national data +#' @param national_data The proportion of sites in each flow condition, daily +#' @param date_start first day of focal month +#' @param date_end last day of focal month +#' @param color_bknd Plot background color +#' @param text_color Color of the text +#' @param axis_text_size manual adjustmet of axis text sizing in theming +#' @param axis_title_bottom_size manual adjustment of axis title size in theming +#' @param axis_title_top_size manual adjustment of top x axis title size in theming +#' @param pal color palette for each bin level +prep_and_plot_national_data <- function(national_data, date_start, date_end, + color_bknd, text_color, axis_text_size, + axis_title_bottom_size, axis_title_top_size, + pal){ + + # to label flow categories + sec_labels <- national_data %>% + filter(date == max(national_data$date)) %>% + distinct(percentile_cond, prop) %>% + mutate(prop = cumsum(prop)) + + plot_nat <- national_data %>% + ggplot(aes(date, prop)) + + geom_area(aes(fill = percentile_bin)) + + theme_classic() + + labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), + y="% of Streamgages") + + scale_fill_manual(values = rev(pal)) + + scale_y_continuous(trans = "reverse", + breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), + labels = c("0%", "25%", "50%", "75%", "100%") + ) + + theme_flowfacet(base = 12, color_bknd, text_color) + + theme(axis.text.y = + element_text(size = axis_text_size, + vjust = 0.5, #c(1, 0), + hjust = 1), + axis.title.y = element_text(size = axis_title_bottom_size, + margin = margin(r = 5)), + axis.title.x.bottom = element_text(size = axis_title_bottom_size, + vjust = -1, + margin = margin(t = 5)), + axis.title.x.top = element_text(size = axis_title_top_size, + vjust = 0, + margin = margin(b = -5)), + axis.text.x.bottom = element_text(size = axis_text_size, + vjust = 1, + # nudge labels up closer to bottom + margin = margin(t = -7))) + + scale_x_date(breaks = seq.Date(date_start, date_end, "1 week"), + position = "bottom", + labels = lubridate::day(seq.Date(date_start, date_end, "1 week")), + sec.axis = dup_axis( + name = "National" + )) + + coord_fixed(ratio = 28, clip = "off") + +} + +#' @description Extract and restyle legend +#' @param plot_nat National data plot +#' @param barwidth Numeric: Define width of each bar in percentile bin legend +#' @param barheight Numeric: Define height of each bar in percentile bin legend +#' @param text_size Numeric: Define size of legend text +restyle_legend_explainer <- function(plot_nat, barwidth, barheight, text_size){ + # Restyle legend + plot_nat_legend <- plot_nat + + guides(fill = guide_colorsteps( + title = "", + nrow = 1, + direction = 'horizontal', + label.position = "bottom", + barwidth = barwidth, + barheight = barheight, + background = element_rect(fill = NA), + show.limits = TRUE + )) + + theme(legend.background = element_rect(fill = NA), + text = element_text(family = font_legend, color = text_color, size = text_size)) + + legend <- get_legend(plot_nat_legend) + +} + +#' @description Cowplot national data image with explainer annotations +#' @param plot_nat National data plot +#' @param date_start first day of focal month +#' @param flow_label legend explainer text +#' @param source_label data source text +#' @param legend restyled legend +#' @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 +cowplot_national_explainer <- function(plot_nat, date_start, flow_label, + source_label, legend, explainer_label, file_png, + width, height, font_legend, text_color){ + + plot_month <- lubridate::month(date_start, label = TRUE, abbr = FALSE) + plot_year <- lubridate::year(date_start) + + # usgs logo + usgs_logo <- magick::image_read('in/usgs_logo.png') %>% + magick::image_colorize(100, text_color) |> magick::image_scale('250x') + + # streamflow title + title_flow <- magick::image_read('in/streamflow.png') |> magick::image_scale('800x') + + plot_margin <- 0.025 + + # background + canvas <- grid::rectGrob( + x = 0, y = 0, + width = 16, height = 9, + gp = grid::gpar(fill = color_bknd, alpha = 1, col = color_bknd) + ) + + #arrows + (normal_range_arrow <- ggplot() + + theme_void()+ + # add arrow using `geom_curve()` + geom_curve(aes(x = 13, y = 3, + xend = 11, yend = 3), + arrow = grid::arrow(length = unit(0.2, 'lines')), + curvature = 0, angle = 100, ncp = 10, + color = text_color, linewidth = 0.2)) + + (low_range_arrow <- ggplot() + + theme_void()+ + # add arrow using `geom_curve()` + geom_curve(aes(x = 13, y = 3, + xend = 11, yend = 3), + arrow = grid::arrow(length = unit(0.2, 'lines')), + curvature = 0, angle = 100, ncp = 10, + color = "#A84E0B", linewidth = 0.2)) + + (high_range_arrow <- ggplot() + + theme_void()+ + # add arrow using `geom_curve()` + geom_curve(aes(x = 13, y = 3, + xend = 11, yend = 3), + arrow = grid::arrow(length = unit(0.2, 'lines')), + curvature = 0, angle = 100, ncp = 10, + color = "#002D5E", linewidth = 0.2)) + + + # # Extract from plot + # plot_legend <- get_legend(restyle_legend) + # + # compose final plot + ggdraw(ylim = c(0,1), + xlim = c(0,1)) + + # a white background + draw_grob(canvas, + x = 0, y = 1, + height = 0.37, width = 0.37, + hjust = 0, vjust = 1) + + # national-level plot + draw_plot(plot_nat+ labs(x = "Day of month") + theme(legend.position = 'none', + text = element_text(family = font_legend, color = text_color)), + x = (1-plot_margin)*0.08, + y = 0.27, + height = 0.54 , + width = (1-plot_margin)*0.8) + + # add legend + draw_plot(legend, + x = (1-plot_margin)*0.5, + y = 0.07, + height = 0.12 , + width = 0.02-plot_margin) + + # 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 = text_color, + lineheight = 1) + + # stylized streamflow title + draw_image(title_flow , + x = plot_margin*2, + y = 1-(1.5*plot_margin), + height = 0.16, + width = 0.74, + hjust = 0, + vjust = 1) + + # percentile info + draw_label(flow_label, + x = (1-plot_margin)*0.18, + y = 0.22, + hjust = 0, + vjust = 1, + fontfamily = font_legend, + color = text_color, + size = 6) + + # add data source + draw_label(source_label, + x = 1-plot_margin*2, y = plot_margin, + fontface = "italic", + size = 5, + hjust = 1, vjust = 0, + fontfamily = font_legend, + color = text_color, + lineheight = 1.1) + + draw_label(explainer_label, + x = 0.5, y = 1-plot_margin*2, + size = 5.5, + hjust = 0, vjust = 1, + fontfamily = font_legend, + color = text_color) + + draw_label("Low\nStreamflow", + x = 0.84, y = 0.355, + size = 5.5, + hjust = 0.5, vjust = 1, + fontfamily = font_legend, + color = "#A84E0B") + + draw_label("High\nStreamflow", + x = 0.84, y = 0.76, + size = 5.5, + hjust = 0.5, vjust = 1, + fontfamily = font_legend, + color = "#002D5E") + + draw_label("Normal Range", + x = 0.88, y = 0.5, + 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, + height = 0.035, + width = 0.05, + hjust = 0, + vjust = 0.5)+ + draw_plot(normal_range_arrow, # for normal range + x = 0.755, + y = 0.495, + height = 0.035, + width = 0.04, + hjust = 0, + vjust = 0.5)+ + draw_plot(low_range_arrow, # for low streamflow + x = 0.755, + y = 0.35, + height = 0.035, + width = 0.055, + hjust = 0, + vjust = 0.5)+ + # add logo + draw_image(usgs_logo, x = plot_margin*2, y = plot_margin*1, width = 0.125, hjust = 0, vjust = 0, halign = 0, valign = 0) + + + # Save and convert file + ggsave(file_png, width = width, height = height, dpi = 300, units = c("px")) + +} + +#' @description Plot national data for intro question background +#' @param national_data The proportion of sites in each flow condition, daily +#' @param percentile_bin bins used to define the percentiles +#' @param pal color palette for each bin level +intro_background <- function(national_data, percentile_bin, pal){ + + (plot_nat_clean <- national_data %>% + ggplot(aes(date, prop)) + + geom_area(aes(fill = percentile_bin), alpha = 0.5) + + scale_fill_manual(values = rev(pal)) + + scale_y_continuous(trans = "reverse", + breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), + labels = c("0%", "25%", "50%", "75%", "100%")) + + coord_fixed(ratio = 28, clip = "off")+ + theme_void()+ + theme(legend.position = "none")) + +} + +#' @description Cowplot intro question image +#' @param plot_nat_clean Plot of national data used for background +#' @param date_start first day of focal month +#' @param font_legend font used for legend text +#' @param width width of final png +#' @param height height of final png +#' @param file_png file path for final png +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, + width = 16, height = 9, + gp = grid::gpar(fill = color_bknd, alpha = 1, col = color_bknd) + ) + + ggdraw(ylim = c(0,1), + xlim = c(0,1)) + + # a white background + draw_grob(canvas, + x = 0, y = 1, + height = 0.37, width = 0.37, + hjust = 0, vjust = 1) + + # 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 do %s's\nstreamflow\nconditions\ncompare to the\npast?", plot_month), + x = 0.05, + y = 0.5, + size = 28, + hjust = 0, + vjust = 0.5, + fontfamily = font_legend, + color = "#222222") + + ggsave(file_png, width = width, height = height, dpi = 300, units = c("px")) + +} \ No newline at end of file From 3ce9568dbc49e5153340df090fbe5e1c3c9a5445 Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Fri, 17 May 2024 15:27:13 -0400 Subject: [PATCH 2/8] add documentaion --- _targets.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_targets.R b/_targets.R index 6f6ef26..83bfc52 100644 --- a/_targets.R +++ b/_targets.R @@ -244,11 +244,13 @@ list( #### explainer images and updated state #### + # updated color palette tar_target( explainer_pal, c("#002D5E", "#0C7182", "#6CB7B0", "#C0C0C0", "#F0DB85", "#AF9423", "#A84E0B") ), + # plot national data for explainer image (slight change in axis titles) tar_target( explainer_national_plot, prep_and_plot_national_data(national_data = flow_national, date_start, date_end, @@ -257,11 +259,13 @@ list( pal = explainer_pal) ), + # isolate legend from updated national plot tar_target( explainer_restyle_legend, restyle_legend_explainer(plot_nat = explainer_national_plot, barwidth = 12, barheight = 0.6, text_size = 6.5) ), + # cowplot national image png for instagram with explainer text tar_target( explainer_flow_national_ig_png, cowplot_national_explainer(plot_nat = explainer_national_plot, date_start, @@ -273,11 +277,13 @@ list( format = "file" ), + # edit national plot to serve as intro question background tar_target( explainer_intro_background, intro_background(national_data = flow_national, percentile_bin, pal = explainer_pal) ), + # cowplot intro question instagram png tar_target( intro_question_ig_png, intro_image(plot_nat_clean = explainer_intro_background, date_start, From 96c926b4a6ff4fb570cef2831143d499e8a721c3 Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Tue, 16 Jul 2024 16:03:33 -0400 Subject: [PATCH 3/8] reduce amount of targets for explainer images, updates to colors, labels, and axes for base plots --- _targets.R | 38 ++------- src/explainer_prep.R | 194 ++++++++++++++++++------------------------- src/plot_cartogram.R | 42 ++++++---- 3 files changed, 117 insertions(+), 157 deletions(-) diff --git a/_targets.R b/_targets.R index 83bfc52..b41595a 100644 --- a/_targets.R +++ b/_targets.R @@ -9,7 +9,8 @@ source("src/plot_cartogram.R") source("src/explainer_prep.R") # wet to dry color scale -pal_wetdry <- c("#002D5E", "#0C7182", "#6CB7B0", "#A7D2D8", "#E0D796", "#AF9423", "#A84E0B") +pal_wetdry <- c("#002D5E", "#0C7182", "#6CB7B0", "#C0C0C0", "#F0DB85", "#AF9423", "#A84E0B") + #c("#002D5E", "#0C7182", "#6CB7B0", "#A7D2D8", "#E0D796", "#AF9423", "#A84E0B") percentile_breaks = c(0, 0.05, 0.1, 0.25, 0.75, 0.9, 0.95, 1) percentile_labels <- c("Driest", "Drier", "Dry", "Normal","Wet","Wetter", "Wettest") color_bknd <- "#F4F4F4" @@ -23,7 +24,8 @@ showtext_opts(dpi = 300, regular.wt = 200, bold.wt = 700) showtext_auto(enable = TRUE) # draw label text -flow_label <- "Flow percentile at USGS streamgages relative\nto the historic record." +flow_label <- "Streamflow percentile at USGS streamgages\nrelative to the historic record." +#"Flow percentile at USGS streamgages relative\nto the historic record." source_label <- "Data: USGS Water Data for the Nation" # to produce the flow cartogram, run tar_make() in the console @@ -163,8 +165,6 @@ list( font_legend), format = "file" ), - - #### explainer image - will be a new target or two #### # Flow timeseries for states - Instagram tar_target( @@ -244,34 +244,12 @@ list( #### explainer images and updated state #### - # updated color palette - tar_target( - explainer_pal, - c("#002D5E", "#0C7182", "#6CB7B0", "#C0C0C0", "#F0DB85", "#AF9423", "#A84E0B") - ), - - # plot national data for explainer image (slight change in axis titles) - tar_target( - explainer_national_plot, - prep_and_plot_national_data(national_data = flow_national, date_start, date_end, - color_bknd, text_color, axis_text_size = 6, - axis_title_bottom_size = 10, axis_title_top_size = 12, - pal = explainer_pal) - ), - - # isolate legend from updated national plot - tar_target( - explainer_restyle_legend, - restyle_legend_explainer(plot_nat = explainer_national_plot, barwidth = 12, barheight = 0.6, text_size = 6.5) - ), - # cowplot national image png for instagram with explainer text tar_target( explainer_flow_national_ig_png, - cowplot_national_explainer(plot_nat = explainer_national_plot, date_start, - flow_label = "Streamflow percentile at USGS streamgages\nrelative to the historic record.", - source_label, legend = explainer_restyle_legend, - explainer_label = "Keep proportions in mind!\n\nMore blue = wetter conditions\nMore yellow/orange = drier conditions", + cowplot_national_explainer(explainer_label = "HOT TIP: Keep proportions in mind!", + blue_label = "More blue = wetter conditions", + orange_label = "More yellow/orange = drier conditions", file_png = "out/explainer_flow_national_ig.png", width = 1080, height = 1080, font_legend, text_color), format = "file" @@ -280,7 +258,7 @@ list( # edit national plot to serve as intro question background tar_target( explainer_intro_background, - intro_background(national_data = flow_national, percentile_bin, pal = explainer_pal) + intro_background(national_data = flow_national, percentile_bin, pal = pal_wetdry) ), # cowplot intro question instagram png diff --git a/src/explainer_prep.R b/src/explainer_prep.R index 7f9e090..7056fd0 100644 --- a/src/explainer_prep.R +++ b/src/explainer_prep.R @@ -8,34 +8,22 @@ #' @param axis_title_bottom_size manual adjustment of axis title size in theming #' @param axis_title_top_size manual adjustment of top x axis title size in theming #' @param pal color palette for each bin level -prep_and_plot_national_data <- function(national_data, date_start, date_end, - color_bknd, text_color, axis_text_size, - axis_title_bottom_size, axis_title_top_size, - pal){ +prep_and_plot_national_data <- function(existing_plot, axis_text_size, + axis_title_bottom_size, date_end, + axis_title_top_size + ){ - # to label flow categories - sec_labels <- national_data %>% - filter(date == max(national_data$date)) %>% - distinct(percentile_cond, prop) %>% - mutate(prop = cumsum(prop)) - - plot_nat <- national_data %>% - ggplot(aes(date, prop)) + - geom_area(aes(fill = percentile_bin)) + - theme_classic() + - labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), + plot_nat_explain <- existing_plot + + labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), # y="% of Streamgages") + - scale_fill_manual(values = rev(pal)) + - scale_y_continuous(trans = "reverse", - breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), - labels = c("0%", "25%", "50%", "75%", "100%") + scale_y_continuous(trans = "reverse", # + breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), # + labels = c("0%", "25%", "50%", "75%", "100%") # ) + - theme_flowfacet(base = 12, color_bknd, text_color) + - theme(axis.text.y = - element_text(size = axis_text_size, - vjust = 0.5, #c(1, 0), - hjust = 1), - axis.title.y = element_text(size = axis_title_bottom_size, + theme(axis.text.y = element_text(size = axis_text_size, # + vjust = 0.5, #c(1, 0), # + hjust = 1), # + axis.title.y = element_text(size = axis_title_bottom_size, # margin = margin(r = 5)), axis.title.x.bottom = element_text(size = axis_title_bottom_size, vjust = -1, @@ -46,14 +34,51 @@ prep_and_plot_national_data <- function(national_data, date_start, date_end, axis.text.x.bottom = element_text(size = axis_text_size, vjust = 1, # nudge labels up closer to bottom - margin = margin(t = -7))) + - scale_x_date(breaks = seq.Date(date_start, date_end, "1 week"), - position = "bottom", - labels = lubridate::day(seq.Date(date_start, date_end, "1 week")), - sec.axis = dup_axis( - name = "National" - )) + - coord_fixed(ratio = 28, clip = "off") + margin = margin(t = -7))) + + + # to label flow categories +# sec_labels <- national_data %>% +# filter(date == max(national_data$date)) %>% +# distinct(percentile_cond, prop) %>% +# mutate(prop = cumsum(prop)) + + # create the plot +# plot_nat <- national_data %>% +# ggplot(aes(date, prop)) + +# geom_area(aes(fill = percentile_bin)) + +# theme_classic() + +# labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), # +# y="% of Streamgages") + # +# scale_fill_manual(values = rev(pal)) + +# scale_y_continuous(trans = "reverse", # +# breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), # +# labels = c("0%", "25%", "50%", "75%", "100%") # +# ) + +# theme_flowfacet(base = 12, color_bknd, text_color) + +# theme(axis.text.y = +# element_text(size = axis_text_size, # +# vjust = 0.5, #c(1, 0), # +# hjust = 1), # +# axis.title.y = element_text(size = axis_title_bottom_size, # +# margin = margin(r = 5)), # +# axis.title.x.bottom = element_text(size = axis_title_bottom_size, +# vjust = -1, +# margin = margin(t = 5)), +# axis.title.x.top = element_text(size = axis_title_top_size, +# vjust = 0, +# margin = margin(b = -5)), +# axis.text.x.bottom = element_text(size = axis_text_size, +# vjust = 1, +# # nudge labels up closer to bottom +# margin = margin(t = -7))) + +# scale_x_date(breaks = seq.Date(date_start, date_end, "1 week"), +# position = "bottom", +# labels = lubridate::day(seq.Date(date_start, date_end, "1 week")), +# sec.axis = dup_axis( +# name = "National" +# )) + +# coord_fixed(ratio = 28, clip = "off") } @@ -94,22 +119,10 @@ restyle_legend_explainer <- function(plot_nat, barwidth, barheight, text_size){ #' @param height height of final png #' @param font_legend font used for legend text #' @param text_color color used for viz text -cowplot_national_explainer <- function(plot_nat, date_start, flow_label, - source_label, legend, explainer_label, file_png, - width, height, font_legend, text_color){ +cowplot_national_explainer <- function(explainer_label, file_png, + width, height, font_legend, text_color, blue_label, orange_label){ - plot_month <- lubridate::month(date_start, label = TRUE, abbr = FALSE) - plot_year <- lubridate::year(date_start) - - # usgs logo - usgs_logo <- magick::image_read('in/usgs_logo.png') %>% - magick::image_colorize(100, text_color) |> magick::image_scale('250x') - - # streamflow title - title_flow <- magick::image_read('in/streamflow.png') |> magick::image_scale('800x') - plot_margin <- 0.025 - # background canvas <- grid::rectGrob( x = 0, y = 0, @@ -145,72 +158,34 @@ cowplot_national_explainer <- function(plot_nat, date_start, flow_label, curvature = 0, angle = 100, ncp = 10, color = "#002D5E", linewidth = 0.2)) - - # # Extract from plot - # plot_legend <- get_legend(restyle_legend) - # + national_plot_png <- magick::image_read("out/flow_national_ig.png") # compose final plot ggdraw(ylim = c(0,1), xlim = c(0,1)) + # a white background draw_grob(canvas, x = 0, y = 1, - height = 0.37, width = 0.37, + height = 1, width = 1, hjust = 0, vjust = 1) + - # national-level plot - draw_plot(plot_nat+ labs(x = "Day of month") + theme(legend.position = 'none', - text = element_text(family = font_legend, color = text_color)), - x = (1-plot_margin)*0.08, - y = 0.27, - height = 0.54 , - width = (1-plot_margin)*0.8) + - # add legend - draw_plot(legend, - x = (1-plot_margin)*0.5, - y = 0.07, - height = 0.12 , - width = 0.02-plot_margin) + - # 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 = text_color, - lineheight = 1) + - # stylized streamflow title - draw_image(title_flow , - x = plot_margin*2, - y = 1-(1.5*plot_margin), - height = 0.16, - width = 0.74, - hjust = 0, - vjust = 1) + - # percentile info - draw_label(flow_label, - x = (1-plot_margin)*0.18, - y = 0.22, - hjust = 0, - vjust = 1, + draw_image(national_plot_png, x = 0, 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 = text_color, - size = 6) + - # add data source - draw_label(source_label, - x = 1-plot_margin*2, y = plot_margin, - fontface = "italic", - size = 5, - hjust = 1, vjust = 0, + color = "#000000")+ #text_color) + + draw_label(blue_label, + x = 0.5, y = 0.91, + size = 5.5, + hjust = 0, vjust = 1, fontfamily = font_legend, - color = text_color, - lineheight = 1.1) + - draw_label(explainer_label, - x = 0.5, y = 1-plot_margin*2, + color = "#002D5E")+ + draw_label(orange_label, + x = 0.5, y = 0.88, size = 5.5, hjust = 0, vjust = 1, fontfamily = font_legend, - color = text_color) + + color = "#A84E0B")+ draw_label("Low\nStreamflow", x = 0.84, y = 0.355, size = 5.5, @@ -223,8 +198,8 @@ cowplot_national_explainer <- function(plot_nat, date_start, flow_label, hjust = 0.5, vjust = 1, fontfamily = font_legend, color = "#002D5E") + - draw_label("Normal Range", - x = 0.88, y = 0.5, + draw_label("Typical\nStreamflow", + x = 0.855, y = 0.5, size = 5.5, hjust = 0.5, vjust = 1, fontfamily = font_legend, @@ -236,11 +211,11 @@ cowplot_national_explainer <- function(plot_nat, date_start, flow_label, width = 0.05, hjust = 0, vjust = 0.5)+ - draw_plot(normal_range_arrow, # for normal range + draw_plot(normal_range_arrow, # for typical streamflow x = 0.755, y = 0.495, height = 0.035, - width = 0.04, + width = 0.05, hjust = 0, vjust = 0.5)+ draw_plot(low_range_arrow, # for low streamflow @@ -249,10 +224,7 @@ cowplot_national_explainer <- function(plot_nat, date_start, flow_label, height = 0.035, width = 0.055, hjust = 0, - vjust = 0.5)+ - # add logo - draw_image(usgs_logo, x = plot_margin*2, y = plot_margin*1, width = 0.125, hjust = 0, vjust = 0, halign = 0, valign = 0) - + vjust = 0.5) # Save and convert file ggsave(file_png, width = width, height = height, dpi = 300, units = c("px")) @@ -332,10 +304,10 @@ intro_image <- function(plot_nat_clean, date_start, font_legend, width, height, width = 0.74, hjust = 0, vjust = 1) + - draw_label(sprintf("How do %s's\nstreamflow\nconditions\ncompare to the\npast?", plot_month), + draw_label(sprintf("How did %s's\nstreamflow\ncompare to the\npast?", plot_month), x = 0.05, y = 0.5, - size = 28, + size = 26, hjust = 0, vjust = 0.5, fontfamily = font_legend, diff --git a/src/plot_cartogram.R b/src/plot_cartogram.R index 0e81159..6f0bdd1 100644 --- a/src/plot_cartogram.R +++ b/src/plot_cartogram.R @@ -97,20 +97,30 @@ plot_national_area <- function(national_data, date_start, date_end, pal, color_b ggplot(aes(date, prop)) + geom_area(aes(fill = percentile_bin)) + theme_classic() + - labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), - y="") + + labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), # + y="% of Streamgages") + + #labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), + # y="") + scale_fill_manual(values = rev(pal)) + - scale_y_continuous(trans = "reverse", - breaks = rev(c(0.05,0.5, 0.95)), - labels = c("0%","gages","100%"), - sec.axis = dup_axis( - labels = c("Dry", "", "Wet") - )) + + scale_y_continuous(trans = "reverse", # + breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), # + labels = c("0%", "25%", "50%", "75%", "100%") # + ) + + #scale_y_continuous(trans = "reverse", + # breaks = rev(c(0.05,0.5, 0.95)), + # labels = c("0%","gages","100%"), + # sec.axis = dup_axis( + # labels = c("Dry", "", "Wet") + # )) + theme_flowfacet(base = 12, color_bknd, text_color) + - theme(axis.text.y = - element_text(size = axis_text_size, - vjust = c(1, 0), - hjust = 1), + theme(#axis.text.y = element_text(size = axis_text_size, + # vjust = c(1, 0), + # hjust = 1), + axis.text.y = element_text(size = axis_text_size, # + vjust = 0.5, #c(1, 0), # + hjust = 1), # + axis.title.y = element_text(size = axis_title_bottom_size, # + margin = margin(r = 5)), axis.title.x.bottom = element_text(size = axis_title_bottom_size, vjust = -1, margin = margin(t = 5)), @@ -182,8 +192,8 @@ combine_plots <- function(file_svg, plot_left, plot_right, date_start, width, he barwidth = 22, barheight = 1, background = element_rect(fill = NA), - show.limits = TRUE, - even.steps = FALSE + show.limits = TRUE#, + #even.steps = FALSE )) + theme(legend.background = element_rect(fill = NA), text = element_text(family = font_legend, color = text_color)) @@ -308,8 +318,8 @@ restyle_legend <- function(plot_nat, text_color, font_legend, barwidth, barheigh barwidth = barwidth, barheight = barheight, background = element_rect(fill = NA), - show.limits = TRUE, - even.steps = FALSE + show.limits = TRUE#, + #even.steps = FALSE )) + theme(legend.background = element_rect(fill = NA), text = element_text(family = font_legend, color = text_color, size = text_size)) From beb607a4fe87da074fb29ca0327d6d796c251068 Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Wed, 17 Jul 2024 12:38:03 -0400 Subject: [PATCH 4/8] taking out unused functions in explainer_prep.R --- _targets.R | 8 ++-- src/explainer_prep.R | 111 +------------------------------------------ 2 files changed, 5 insertions(+), 114 deletions(-) diff --git a/_targets.R b/_targets.R index b41595a..2e12596 100644 --- a/_targets.R +++ b/_targets.R @@ -244,7 +244,7 @@ list( #### explainer images and updated state #### - # cowplot national image png for instagram with explainer text + # cowplot the national plot png for instagram with explainer text tar_target( explainer_flow_national_ig_png, cowplot_national_explainer(explainer_label = "HOT TIP: Keep proportions in mind!", @@ -255,13 +255,13 @@ list( format = "file" ), - # edit national plot to serve as intro question background + # create national plot with a lower alpha value to serve as intro question background tar_target( explainer_intro_background, - intro_background(national_data = flow_national, percentile_bin, pal = pal_wetdry) + intro_background(national_data = flow_national, percentile_bin, pal = pal_wetdry) ), - # cowplot intro question instagram png + # cowplot the intro question instagram png tar_target( intro_question_ig_png, intro_image(plot_nat_clean = explainer_intro_background, date_start, diff --git a/src/explainer_prep.R b/src/explainer_prep.R index 7056fd0..834c66d 100644 --- a/src/explainer_prep.R +++ b/src/explainer_prep.R @@ -1,112 +1,3 @@ -#' @description Prep and plot national data -#' @param national_data The proportion of sites in each flow condition, daily -#' @param date_start first day of focal month -#' @param date_end last day of focal month -#' @param color_bknd Plot background color -#' @param text_color Color of the text -#' @param axis_text_size manual adjustmet of axis text sizing in theming -#' @param axis_title_bottom_size manual adjustment of axis title size in theming -#' @param axis_title_top_size manual adjustment of top x axis title size in theming -#' @param pal color palette for each bin level -prep_and_plot_national_data <- function(existing_plot, axis_text_size, - axis_title_bottom_size, date_end, - axis_title_top_size - ){ - - plot_nat_explain <- existing_plot + - labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), # - y="% of Streamgages") + - scale_y_continuous(trans = "reverse", # - breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), # - labels = c("0%", "25%", "50%", "75%", "100%") # - ) + - theme(axis.text.y = element_text(size = axis_text_size, # - vjust = 0.5, #c(1, 0), # - hjust = 1), # - axis.title.y = element_text(size = axis_title_bottom_size, # - margin = margin(r = 5)), - axis.title.x.bottom = element_text(size = axis_title_bottom_size, - vjust = -1, - margin = margin(t = 5)), - axis.title.x.top = element_text(size = axis_title_top_size, - vjust = 0, - margin = margin(b = -5)), - axis.text.x.bottom = element_text(size = axis_text_size, - vjust = 1, - # nudge labels up closer to bottom - margin = margin(t = -7))) - - - # to label flow categories -# sec_labels <- national_data %>% -# filter(date == max(national_data$date)) %>% -# distinct(percentile_cond, prop) %>% -# mutate(prop = cumsum(prop)) - - # create the plot -# plot_nat <- national_data %>% -# ggplot(aes(date, prop)) + -# geom_area(aes(fill = percentile_bin)) + -# theme_classic() + -# labs(x = lubridate::month(date_end - 30, label = TRUE, abbr = FALSE), # -# y="% of Streamgages") + # -# scale_fill_manual(values = rev(pal)) + -# scale_y_continuous(trans = "reverse", # -# breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), # -# labels = c("0%", "25%", "50%", "75%", "100%") # -# ) + -# theme_flowfacet(base = 12, color_bknd, text_color) + -# theme(axis.text.y = -# element_text(size = axis_text_size, # -# vjust = 0.5, #c(1, 0), # -# hjust = 1), # -# axis.title.y = element_text(size = axis_title_bottom_size, # -# margin = margin(r = 5)), # -# axis.title.x.bottom = element_text(size = axis_title_bottom_size, -# vjust = -1, -# margin = margin(t = 5)), -# axis.title.x.top = element_text(size = axis_title_top_size, -# vjust = 0, -# margin = margin(b = -5)), -# axis.text.x.bottom = element_text(size = axis_text_size, -# vjust = 1, -# # nudge labels up closer to bottom -# margin = margin(t = -7))) + -# scale_x_date(breaks = seq.Date(date_start, date_end, "1 week"), -# position = "bottom", -# labels = lubridate::day(seq.Date(date_start, date_end, "1 week")), -# sec.axis = dup_axis( -# name = "National" -# )) + -# coord_fixed(ratio = 28, clip = "off") - -} - -#' @description Extract and restyle legend -#' @param plot_nat National data plot -#' @param barwidth Numeric: Define width of each bar in percentile bin legend -#' @param barheight Numeric: Define height of each bar in percentile bin legend -#' @param text_size Numeric: Define size of legend text -restyle_legend_explainer <- function(plot_nat, barwidth, barheight, text_size){ - # Restyle legend - plot_nat_legend <- plot_nat + - guides(fill = guide_colorsteps( - title = "", - nrow = 1, - direction = 'horizontal', - label.position = "bottom", - barwidth = barwidth, - barheight = barheight, - background = element_rect(fill = NA), - show.limits = TRUE - )) + - theme(legend.background = element_rect(fill = NA), - text = element_text(family = font_legend, color = text_color, size = text_size)) - - legend <- get_legend(plot_nat_legend) - -} - #' @description Cowplot national data image with explainer annotations #' @param plot_nat National data plot #' @param date_start first day of focal month @@ -235,7 +126,7 @@ cowplot_national_explainer <- function(explainer_label, file_png, #' @param national_data The proportion of sites in each flow condition, daily #' @param percentile_bin bins used to define the percentiles #' @param pal color palette for each bin level -intro_background <- function(national_data, percentile_bin, pal){ +intro_background <- function(national_data, percentile_bin, pal){ (plot_nat_clean <- national_data %>% ggplot(aes(date, prop)) + From 7162459900f98dc18d9140a595d3e8a2b9c733be Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Thu, 18 Jul 2024 11:22:16 -0400 Subject: [PATCH 5/8] cleaning up code and updating documentation --- src/explainer_prep.R | 64 +++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/src/explainer_prep.R b/src/explainer_prep.R index 834c66d..bc7b917 100644 --- a/src/explainer_prep.R +++ b/src/explainer_prep.R @@ -1,15 +1,12 @@ #' @description Cowplot national data image with explainer annotations -#' @param plot_nat National data plot -#' @param date_start first day of focal month -#' @param flow_label legend explainer text -#' @param source_label data source text -#' @param legend restyled legend #' @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, width, height, font_legend, text_color, blue_label, orange_label){ @@ -58,7 +55,11 @@ cowplot_national_explainer <- function(explainer_label, file_png, x = 0, y = 1, height = 1, width = 1, hjust = 0, vjust = 1) + - draw_image(national_plot_png, x = 0, y = 0, width = 1, hjust = 0, vjust = 0, halign = 0, valign = 0)+ + draw_image(national_plot_png, + x = 0, 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, @@ -96,26 +97,17 @@ cowplot_national_explainer <- function(explainer_label, file_png, fontfamily = font_legend, color = text_color) + draw_plot(high_range_arrow, # for high streamflow - x = 0.755, - y = 0.755, - height = 0.035, - width = 0.05, - hjust = 0, - vjust = 0.5)+ + x = 0.755, y = 0.755, + height = 0.035, width = 0.05, + hjust = 0, vjust = 0.5)+ draw_plot(normal_range_arrow, # for typical streamflow - x = 0.755, - y = 0.495, - height = 0.035, - width = 0.05, - hjust = 0, - vjust = 0.5)+ + x = 0.755, y = 0.495, + height = 0.035, width = 0.05, + hjust = 0, vjust = 0.5)+ draw_plot(low_range_arrow, # for low streamflow - x = 0.755, - y = 0.35, - height = 0.035, - width = 0.055, - hjust = 0, - vjust = 0.5) + x = 0.755, y = 0.35, + height = 0.035, width = 0.055, + hjust = 0, vjust = 0.5) # Save and convert file ggsave(file_png, width = width, height = height, dpi = 300, units = c("px")) @@ -174,33 +166,25 @@ intro_image <- function(plot_nat_clean, date_start, font_legend, width, height, hjust = 0, vjust = 1) + # national-level plot draw_plot(plot_nat_clean, - x = -0.055, - y = -0.09, - height = 1.18, - width = 1.18)+ + 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, + 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) + + 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), - x = 0.05, - y = 0.5, + x = 0.05, y = 0.5, size = 26, - hjust = 0, - vjust = 0.5, + hjust = 0, vjust = 0.5, fontfamily = font_legend, color = "#222222") From 94aab9561c504999ed2fccbb7fe06337c098f7be Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Thu, 18 Jul 2024 12:45:22 -0400 Subject: [PATCH 6/8] updated for june streamflow, fix explainer png target --- _targets.R | 3 ++- src/explainer_prep.R | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/_targets.R b/_targets.R index 4eb77de..65c1a6a 100644 --- a/_targets.R +++ b/_targets.R @@ -247,7 +247,8 @@ list( # cowplot the national plot png for instagram with explainer text tar_target( explainer_flow_national_ig_png, - cowplot_national_explainer(explainer_label = "HOT TIP: Keep proportions in mind!", + 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", file_png = "out/explainer_flow_national_ig.png", diff --git a/src/explainer_prep.R b/src/explainer_prep.R index bc7b917..401dc07 100644 --- a/src/explainer_prep.R +++ b/src/explainer_prep.R @@ -7,7 +7,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, +cowplot_national_explainer <- function(explainer_label, file_png, national_plot_png, width, height, font_legend, text_color, blue_label, orange_label){ plot_margin <- 0.025 @@ -46,7 +46,7 @@ cowplot_national_explainer <- function(explainer_label, file_png, curvature = 0, angle = 100, ncp = 10, color = "#002D5E", linewidth = 0.2)) - national_plot_png <- magick::image_read("out/flow_national_ig.png") + og_plot_png <- magick::image_read(national_plot_png) # compose final plot ggdraw(ylim = c(0,1), xlim = c(0,1)) + @@ -55,7 +55,7 @@ cowplot_national_explainer <- function(explainer_label, file_png, x = 0, y = 1, height = 1, width = 1, hjust = 0, vjust = 1) + - draw_image(national_plot_png, + draw_image(og_plot_png, x = 0, y = 0, width = 1, hjust = 0, vjust = 0, From 0c2527b24c95c716a4c2af260d99a8ec9660c290 Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Thu, 18 Jul 2024 13:41:39 -0400 Subject: [PATCH 7/8] adding arguments to explainer cowplot function --- _targets.R | 7 ++++++- src/explainer_prep.R | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/_targets.R b/_targets.R index 65c1a6a..b7756c4 100644 --- a/_targets.R +++ b/_targets.R @@ -252,7 +252,12 @@ list( blue_label = "More blue = wetter conditions", orange_label = "More yellow/orange = drier conditions", file_png = "out/explainer_flow_national_ig.png", - width = 1080, height = 1080, font_legend, text_color), + 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.5, typ_arr_ypos = 0.495), format = "file" ), diff --git a/src/explainer_prep.R b/src/explainer_prep.R index 401dc07..86f78d6 100644 --- a/src/explainer_prep.R +++ b/src/explainer_prep.R @@ -8,8 +8,9 @@ #' @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, - width, height, font_legend, text_color, blue_label, orange_label){ - + 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 plot_margin <- 0.025 # background canvas <- grid::rectGrob( @@ -35,7 +36,7 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_ xend = 11, yend = 3), arrow = grid::arrow(length = unit(0.2, 'lines')), curvature = 0, angle = 100, ncp = 10, - color = "#A84E0B", linewidth = 0.2)) + color = low_col, linewidth = 0.2)) (high_range_arrow <- ggplot() + theme_void()+ @@ -44,7 +45,7 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_ xend = 11, yend = 3), arrow = grid::arrow(length = unit(0.2, 'lines')), curvature = 0, angle = 100, ncp = 10, - color = "#002D5E", linewidth = 0.2)) + color = high_col, linewidth = 0.2)) og_plot_png <- magick::image_read(national_plot_png) # compose final plot @@ -65,33 +66,33 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_ size = 5.5, hjust = 0, vjust = 1, fontfamily = font_legend, - color = "#000000")+ #text_color) + + color = "#000000")+ draw_label(blue_label, x = 0.5, y = 0.91, size = 5.5, hjust = 0, vjust = 1, fontfamily = font_legend, - color = "#002D5E")+ + color = high_col)+ draw_label(orange_label, x = 0.5, y = 0.88, size = 5.5, hjust = 0, vjust = 1, fontfamily = font_legend, - color = "#A84E0B")+ - draw_label("Low\nStreamflow", + color = low_col)+ + draw_label(low_lab, x = 0.84, y = 0.355, size = 5.5, hjust = 0.5, vjust = 1, fontfamily = font_legend, - color = "#A84E0B") + - draw_label("High\nStreamflow", + color = low_col) + + draw_label(high_lab, x = 0.84, y = 0.76, size = 5.5, hjust = 0.5, vjust = 1, fontfamily = font_legend, - color = "#002D5E") + - draw_label("Typical\nStreamflow", - x = 0.855, y = 0.5, + color = high_col) + + draw_label(typ_lab, + x = 0.855, y = typ_lab_ypos, size = 5.5, hjust = 0.5, vjust = 1, fontfamily = font_legend, @@ -101,7 +102,7 @@ cowplot_national_explainer <- function(explainer_label, file_png, national_plot_ height = 0.035, width = 0.05, hjust = 0, vjust = 0.5)+ draw_plot(normal_range_arrow, # for typical streamflow - x = 0.755, y = 0.495, + x = 0.755, y = typ_arr_ypos, height = 0.035, width = 0.05, hjust = 0, vjust = 0.5)+ draw_plot(low_range_arrow, # for low streamflow From 267c70660ae5b35f3895b5288c8df0b6cf16d230 Mon Sep 17 00:00:00 2001 From: Kaysa Vaarre-Lamoureux Date: Thu, 18 Jul 2024 16:13:04 -0400 Subject: [PATCH 8/8] deleting commented out code --- src/plot_cartogram.R | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/plot_cartogram.R b/src/plot_cartogram.R index 8fdebbd..a98ee2e 100644 --- a/src/plot_cartogram.R +++ b/src/plot_cartogram.R @@ -106,21 +106,12 @@ plot_national_area <- function(national_data, date_start, date_end, pal, color_b breaks = rev(c(0, 0.25, 0.5, 0.75, 1)), # labels = c("0%", "25%", "50%", "75%", "100%") # ) + - #scale_y_continuous(trans = "reverse", - # breaks = rev(c(0.05,0.5, 0.95)), - # labels = c("0%","gages","100%"), - # sec.axis = dup_axis( - # labels = c("Dry", "", "Wet") - # )) + theme_flowfacet(base = 12, color_bknd, text_color) + - theme(#axis.text.y = element_text(size = axis_text_size, - # vjust = c(1, 0), - # hjust = 1), - axis.text.y = element_text(size = axis_text_size, # - vjust = 0.5, #c(1, 0), # - hjust = 1), # - axis.title.y = element_text(size = axis_title_bottom_size, # - margin = margin(r = 5)), + theme(axis.text.y = element_text(size = axis_text_size, # + vjust = 0.5, #c(1, 0), # + hjust = 1), # + axis.title.y = element_text(size = axis_title_bottom_size, # + margin = margin(r = 5)), axis.title.x.bottom = element_text(size = axis_title_bottom_size, vjust = -1, margin = margin(t = 5)),