From e80f8cff68087d974b4e46ceee4ddffa2e3606bb Mon Sep 17 00:00:00 2001 From: Connor Rothschild Date: Thu, 26 Mar 2020 12:29:09 -0500 Subject: [PATCH 1/5] add number/date formatting to tooltip --- R/plots.R | 2 +- app.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/plots.R b/R/plots.R index 90f5ae5..7c5a387 100644 --- a/R/plots.R +++ b/R/plots.R @@ -79,7 +79,7 @@ stats.default <- function(df, gg <- ggplot(df, aes(x = x_vec, y = y_vec, color = color_vec, label = stringr::str_wrap(label, width = str_width))) + geom_line() + - ggiraph::geom_point_interactive(tooltip = glue::glue("{tt_place}: {color_vec}
Date: {x_vec}
{tt_name}: {y_vec}")) + + ggiraph::geom_point_interactive(tooltip = glue::glue("{tt_place}: {color_vec}
Date: {format(x_vec, '%B %d, %Y')}
{tt_name}: {comma(y_vec)}")) + scale_color_manual(legend_lab, values = as.vector(tpltheme::tpl_palettes$categorical)) + scale_y_continuous(labels = scales::comma_format()) + diff --git a/app.R b/app.R index 4568336..b5ca426 100644 --- a/app.R +++ b/app.R @@ -1,5 +1,6 @@ library(magrittr) library(ggplot2) +library(scales) rm(list = ls()) options(encoding = "UTF-8") From 472c30ecfbd1226e8f1caa8e59a925607b49d435 Mon Sep 17 00:00:00 2001 From: Connor Rothschild Date: Thu, 26 Mar 2020 17:40:36 -0500 Subject: [PATCH 2/5] changed geom_label to be slightly smaller, made input = 1 choice --- R/plots.R | 2 +- R/state_stats.R | 2 +- R/world_stats.R | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/plots.R b/R/plots.R index 7c5a387..1c5a890 100644 --- a/R/plots.R +++ b/R/plots.R @@ -60,7 +60,7 @@ stats.default <- function(df, y_lab = NULL, x_lab = "Date", legend_lab = "States", - size = 3, + size = 2.5, hjust = 0, nudge_x = 8, box_padding = .5, diff --git a/R/state_stats.R b/R/state_stats.R index 0962af4..0dc06cf 100644 --- a/R/state_stats.R +++ b/R/state_stats.R @@ -54,7 +54,7 @@ widget.state_event_picker <- function() { choices = update_timeline.state(state) %>% dplyr::distinct(event) %>% dplyr::pull(event), - multiple = TRUE, + multiple = FALSE, options = list( `actions-box` = TRUE, size = 10, diff --git a/R/world_stats.R b/R/world_stats.R index de98853..526581c 100644 --- a/R/world_stats.R +++ b/R/world_stats.R @@ -75,7 +75,7 @@ widget.country_event_picker <- function() { choices = update_timeline.country(world) %>% dplyr::distinct(event) %>% dplyr::pull(event), - multiple = TRUE, + multiple = FALSE, options = list( `actions-box` = TRUE, size = 10, From 62b4a7d93985c3d8e2240841684dac0a404b1c16 Mon Sep 17 00:00:00 2001 From: Connor Rothschild Date: Thu, 26 Mar 2020 17:40:50 -0500 Subject: [PATCH 3/5] a new idea for a timeline that could go directly above or below the plot --- R/timeline_idea.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 R/timeline_idea.R diff --git a/R/timeline_idea.R b/R/timeline_idea.R new file mode 100644 index 0000000..0accee7 --- /dev/null +++ b/R/timeline_idea.R @@ -0,0 +1,15 @@ +#devtools::install_github("shosaco/vistime") +# library(vistime) +# +# country_test <- update_timeline.country(world) +# +# china <- country_test %>% +# dplyr::filter(countryName == "China") %>% +# dplyr::mutate(test = strwrap(label,30, simplify = FALSE)) +# +# china$text <- sapply(china$test, paste, collapse="
") +# +# china <- china %>% +# dplyr::mutate(label_line_breaks = glue::glue("{countryName} on {Date}:
{text}")) +# +# vistime(china, start = "Date", tooltips = "label_line_breaks", show_labels = FALSE) From 2e941c76386e5cfd83b747e9edf541ad9f1c220a Mon Sep 17 00:00:00 2001 From: Connor Rothschild Date: Thu, 26 Mar 2020 18:01:47 -0500 Subject: [PATCH 4/5] standardize timeline to be girafe --- R/timeline_idea.R | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/R/timeline_idea.R b/R/timeline_idea.R index 0accee7..e230d1e 100644 --- a/R/timeline_idea.R +++ b/R/timeline_idea.R @@ -1,15 +1,28 @@ -#devtools::install_github("shosaco/vistime") -# library(vistime) +# #devtools::install_github("shosaco/vistime") +# # library(vistime) # # country_test <- update_timeline.country(world) # -# china <- country_test %>% -# dplyr::filter(countryName == "China") %>% -# dplyr::mutate(test = strwrap(label,30, simplify = FALSE)) +# china <- country_test %>% +# dplyr::filter(countryName == "China") %>% +# dplyr::mutate(test = strwrap(label,30, simplify = FALSE)) # # china$text <- sapply(china$test, paste, collapse="
") -# -# china <- china %>% +# +# china <- china %>% # dplyr::mutate(label_line_breaks = glue::glue("{countryName} on {Date}:
{text}")) # -# vistime(china, start = "Date", tooltips = "label_line_breaks", show_labels = FALSE) +# # vistime(china, start = "Date", tooltips = "label_line_breaks", show_labels = FALSE) +# +# timeline <- ggplot(china, aes(x = Date, y = 1, label = label, tooltip = glue::glue("{countryName} on {format(Date, '%B %d, %Y')}:
{label}"))) + +# ggiraph::geom_point_interactive(size = 3) + +# labs(y = element_blank(), +# x = element_blank()) + +# theme( +# axis.line.y.left = element_blank(), +# axis.text.y.left = element_blank(), +# axis.line.x.bottom = element_blank(), +# axis.ticks.x = element_blank() +# ) +# +# ggiraph::girafe(ggobj = timeline) From b8895d28d3935c9c52b417f22c90617dbcb15083 Mon Sep 17 00:00:00 2001 From: Connor Rothschild Date: Thu, 26 Mar 2020 20:39:58 -0500 Subject: [PATCH 5/5] put timeline in UseMethod format --- R/plots.R | 31 +++++++++++++++++++++++++++++++ R/timeline_idea.R | 6 +++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/R/plots.R b/R/plots.R index 1c5a890..b543d71 100644 --- a/R/plots.R +++ b/R/plots.R @@ -122,3 +122,34 @@ stats.default <- function(df, # print(gg) } + +timeline <- function(...) UseMethod("timeline") + +timeline.default <- function(df, + alpha = 1, + x = "Date", + y = 1, + y_lab = NULL, + x_lab = "Date", + legend_lab = "States", + size = 3) { + + gg <- ggplot(df, aes(x = Date, y = 1, label = label, tooltip = glue::glue("{countryName} on {format(Date, '%B %d, %Y')}:
{label}"))) + + ggiraph::geom_point_interactive(size = size) + + labs(y = element_blank(), + x = x_lab) + + scale_color_manual(legend_lab, + values = as.vector(tpltheme::tpl_palettes$categorical)) + + gg <- gg + + theme( + axis.line.y.left = element_blank(), + axis.text.y.left = element_blank(), + axis.line.x.bottom = element_blank(), + axis.ticks.x = element_blank() + ) + + gg <- ggiraph::girafe(ggobj = gg) + +} + diff --git a/R/timeline_idea.R b/R/timeline_idea.R index e230d1e..0cc80ae 100644 --- a/R/timeline_idea.R +++ b/R/timeline_idea.R @@ -1,6 +1,6 @@ -# #devtools::install_github("shosaco/vistime") +# # devtools::install_github("shosaco/vistime") # # library(vistime) -# + # country_test <- update_timeline.country(world) # # china <- country_test %>% @@ -20,7 +20,7 @@ # x = element_blank()) + # theme( # axis.line.y.left = element_blank(), -# axis.text.y.left = element_blank(), +# axis.text.y.left = element_blank(), # axis.line.x.bottom = element_blank(), # axis.ticks.x = element_blank() # )