diff --git a/DESCRIPTION b/DESCRIPTION index 0993efb..a6e093a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,5 +19,5 @@ Suggests: covr, hrbrthemes, dplyr, forcats, knitr, rmarkdown, Depends: R (>= 3.2.0) Imports: ggplot2, grid Roxygen: list(markdown = TRUE) -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 VignetteBuilder: knitr diff --git a/data-raw/2019-12-19-us-elections-debate-speaking-time.html b/data-raw/2019-12-19-us-elections-debate-speaking-time.html new file mode 100644 index 0000000..c29e55a --- /dev/null +++ b/data-raw/2019-12-19-us-elections-debate-speaking-time.html @@ -0,0 +1,586 @@ + + + + Which Candidates Got the Most Speaking Time in the Democratic Debate - The New York Times + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Advertisement

Which Candidates Got the Most Speaking Time in the Democratic Debate

+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ + + +

+ + How Long Each Candidate Spoke + + + + +

+ + + + + + +
+ + + + + + +
+ +

Impeachment

+
+ +
+ +

Economy

+
+ +
+ +

Climate change

+
+ +
+ +

Racial equality

+
+ +
+ +

Foreign policy

+
+ +
+ +

Electability

+
+ +
+ +

Party strategy

+
+ +
+ +

Human rights

+
+ +
+ +

Immigration

+
+ +
+ +

Health care

+
+ + + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + Note: Each bar segment represents the length of a candidate’s response to a question. +
+ + +
+ +

+ Senator Bernie Sanders of Vermont and Senator Amy Klobuchar of Minnesota got the most speaking time in the sixth Democratic presidential debate. +

+

+ The candidates sparred on party strategy, electability and whether campaigns should accept money from wealthy donors. Discussion of foreign policy lasted 15 minutes, more than any other topic, while climate change was the focus for 11 minutes. Candidates also defended the rights of the press, people with disabilities and transgender people. +

+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + +
+ +

+ Get full coverage of the Democratic presidential debate from the Times. +

+ +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/data-raw/debates2019.R b/data-raw/debates2019.R index f65d692..fff5bca 100644 --- a/data-raw/debates2019.R +++ b/data-raw/debates2019.R @@ -23,6 +23,7 @@ if (!file.exists(here::here("data-raw/2019-07-31-us-elections-debate-speaking-ti if (!file.exists(here::here("data-raw/2019-09-12-us-elections-debate-speaking-time.html"))) download.file("https://www.nytimes.com/interactive/2019/09/12/us/elections/debate-speaking-time.html", here::here("data-raw/2019-09-12-us-elections-debate-speaking-time.html")) if (!file.exists(here::here("data-raw/2019-10-15-us-elections-debate-speaking-time.html"))) download.file("https://www.nytimes.com/interactive/2019/10/15/us/elections/debate-speaking-time.html", here::here("data-raw/2019-10-15-us-elections-debate-speaking-time.html")) if (!file.exists(here::here("data-raw/2019-11-20-us-elections-debate-speaking-time.html"))) download.file("https://www.nytimes.com/interactive/2019/11/20/us/elections/debate-speaking-time.html", here::here("data-raw/2019-11-20-us-elections-debate-speaking-time.html")) +if (!file.exists(here::here("data-raw/2019-12-19-us-elections-debate-speaking-time.html"))) download.file("https://www.nytimes.com/interactive/2019/12/19/us/elections/debate-speaking-time.html", here::here("data-raw/2019-12-19-us-elections-debate-speaking-time.html")) read_html(here::here("data-raw/2019-06-26-us-elections-debate-speaking-time.html")) %>% html_nodes(xpath = ".//script[contains(., 'NYTG_DEMDEBATES')]") %>% @@ -353,6 +354,64 @@ read_html(here::here("data-raw/2019-11-20-us-elections-debate-speaking-time.html ) %>% as_tibble() -> nov_day_1 + +read_html(here::here("data-raw/2019-12-19-us-elections-debate-speaking-time.html")) %>% + html_nodes(xpath = ".//script[contains(., 'NYTG_DEMDEBATES')]") %>% + html_text() %>% + stri_split_lines() %>% + unlist() %>% + .[3] %>% + stri_replace_first_regex("^.*NYTG_DEMDEBATES = ", "") %>% + jsonlite::fromJSON() %>% + as_tibble() %>% + mutate( + elapsed = as.numeric(elapsed)/60, + debate_date = as.Date("2019-12-19"), + speaker = stri_trans_totitle(speaker), + timestamp = parse_time(timestamp), + debate_group = 6, + night = 1 + ) %>% + filter(speaker != "") %>% + mutate( + topic = case_when( + topic == "" ~ "Other", + grepl("climate", topic) ~ "Climate", + grepl("closing", topic) ~ "Closing", + grepl("judges", topic) ~ "Judges", + grepl("race", topic) ~ "Race", + grepl("education", topic) ~ "Education", + grepl("human-rights", topic) ~ "Human Rights", + grepl("criminal-justice", topic) ~ "Criminal Justice", + grepl("electability", topic) ~ "Electability", + grepl("election-reform", topic) ~ "Election Reform", + grepl("executive-power", topic) ~ "Executive Power", + grepl("candidate-age", topic) ~ "Age", + grepl("foreign-policy", topic) ~ "Foreign Policy", + grepl("gun-control", topic) ~ "Gun Control", + grepl("health-care", topic) ~ "Healthcare", + grepl("immigration", topic) ~ "Immigration", + grepl("impeachment", topic) ~ "Impeachment", + grepl("income-inequality", topic) ~ "Income Inequality", + grepl("economy", topic) ~ "Economy", + grepl("middle-east policy", topic) ~ "Foreign Policy", + grepl("opioids", topic) ~ "Opioids", + grepl("party-strategy", topic) ~ "Party Strategy", + grepl("public-service", topic) ~ "Public Service", + grepl("tech-companies", topic) ~ "Tech Companies", + grepl("white-supremacist violence", topic) ~ "White-Supremacy", + grepl("womens-issues", topic) ~ "Women's Rights", + topic == "" ~ "Other", + TRUE ~ topic + ) + ) %>% + filter( + !is.na(timestamp), + speaker != "", + speaker != "Moderator" + ) %>% + as_tibble() -> dec_day_1 + bind_rows( jun_day_1, jun_day_2, @@ -360,8 +419,13 @@ bind_rows( jul_day_2, sep_day_1, oct_day_1, - nov_day_1 -) -> debates2019 + nov_day_1, + dec_day_1 +) %>% + mutate(topic = case_when( + grepl("elect.*form", topic, ignore.case = TRUE) ~ "Election Reform", + TRUE ~ topic + )) -> debates2019 usethis::use_data(debates2019, overwrite = TRUE) diff --git a/data/debates2019.rda b/data/debates2019.rda index 40336f6..7347a0b 100644 Binary files a/data/debates2019.rda and b/data/debates2019.rda differ diff --git a/man/geom_chicklet.Rd b/man/geom_chicklet.Rd index c26ce82..88be447 100644 --- a/man/geom_chicklet.Rd +++ b/man/geom_chicklet.Rd @@ -7,16 +7,23 @@ \title{Chicklet (rounded segmented column) charts} \format{An object of class \code{GeomChicklet} (inherits from \code{GeomRrect}, \code{Geom}, \code{ggproto}, \code{gg}) of length 7.} \usage{ -geom_chicklet(mapping = NULL, data = NULL, +geom_chicklet( + mapping = NULL, + data = NULL, position = ggplot2::position_stack(reverse = TRUE), - radius = grid::unit(3, "pt"), ..., width = NULL, na.rm = FALSE, - show.legend = NA, inherit.aes = TRUE) + radius = grid::unit(3, "pt"), + ..., + width = NULL, + na.rm = FALSE, + show.legend = NA, + inherit.aes = TRUE +) GeomChicklet } \arguments{ -\item{mapping}{Set of aesthetic mappings created by \code{\link[=aes]{aes()}} or -\code{\link[=aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the +\item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}} or +\code{\link[ggplot2:aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the default), it is combined with the default mapping at the top level of the plot. You must supply \code{mapping} if there is no plot mapping.} @@ -24,11 +31,11 @@ plot. You must supply \code{mapping} if there is no plot mapping.} options: If \code{NULL}, the default, the data is inherited from the plot -data as specified in the call to \code{\link[=ggplot]{ggplot()}}. +data as specified in the call to \code{\link[ggplot2:ggplot]{ggplot()}}. A \code{data.frame}, or other object, will override the plot data. All objects will be fortified to produce a data frame. See -\code{\link[=fortify]{fortify()}} for which variables will be created. +\code{\link[ggplot2:fortify]{fortify()}} for which variables will be created. A \code{function} will be called with a single argument, the plot data. The return value must be a \code{data.frame}, and @@ -40,7 +47,7 @@ a call to a position adjustment function.} \item{radius}{corner radius (default 3pt)} -\item{...}{Other arguments passed on to \code{\link[=layer]{layer()}}. These are +\item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are often aesthetics, used to set an aesthetic to a fixed value, like \code{colour = "red"} or \code{size = 3}. They may also be parameters to the paired geom/stat.} @@ -59,7 +66,7 @@ display.} \item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from -the default plot specification, e.g. \code{\link[=borders]{borders()}}.} +the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.} } \description{ This geom behaves much like \code{\link[ggplot2:geom_col]{ggplot2::geom_col()}} but provides the option to