Browse Source

dec debate

master
boB Rudis 1 year ago
parent
commit
cbe43d1fa5
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
5 changed files with 669 additions and 12 deletions
  1. +1
    -1
      DESCRIPTION
  2. +586
    -0
      data-raw/2019-12-19-us-elections-debate-speaking-time.html
  3. +66
    -2
      data-raw/debates2019.R
  4. BIN
      data/debates2019.rda
  5. +16
    -9
      man/geom_chicklet.Rd

+ 1
- 1
DESCRIPTION View File

@ -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

+ 586
- 0
data-raw/2019-12-19-us-elections-debate-speaking-time.html
File diff suppressed because it is too large
View File


+ 66
- 2
data-raw/debates2019.R View File

@ -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)

BIN
data/debates2019.rda View File


+ 16
- 9
man/geom_chicklet.Rd View File

@ -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


Loading…
Cancel
Save