Browse Source

latest debate - jan 2020

master
boB Rudis 1 year ago
parent
commit
dd94de8ea8
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
6 changed files with 680 additions and 8 deletions
  1. +2
    -2
      DESCRIPTION
  2. +3
    -0
      NEWS.md
  3. +4
    -4
      README.md
  4. +607
    -0
      data-raw/2020-01-14-us-elections-debate-speaking-time.html
  5. +64
    -2
      data-raw/debates2019.R
  6. BIN
      data/debates2019.rda

+ 2
- 2
DESCRIPTION View File

@ -1,8 +1,8 @@
Package: ggchicklet
Type: Package
Title: Create 'Chicklet' (Rounded Segmented Column) Charts
Version: 0.3.0
Date: 2019-12-20
Version: 0.4.0
Date: 2020-01-14
Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role =
c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")),
person("Antoine", "Bichat", role = "ctb") )


+ 3
- 0
NEWS.md View File

@ -1,2 +1,5 @@
0.4.0
* Data updated for latest debate
0.1.0
* Initial release

+ 4
- 4
README.md View File

@ -58,7 +58,7 @@ library(ggchicklet)
# current version
packageVersion("ggchicklet")
## [1] '0.2.0'
## [1] '0.4.0'
```
### From the NYTimes
@ -118,9 +118,9 @@ debates2019 %>%
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | ---: | ---: | ----------: | ---: | -------: | ---: |
| HTML | 8 | 0.44 | 8679 | 0.93 | 2364 | 0.97 | 350 | 0.63 |
| R | 8 | 0.44 | 513 | 0.06 | 38 | 0.02 | 122 | 0.22 |
| Rmd | 2 | 0.11 | 117 | 0.01 | 45 | 0.02 | 85 | 0.15 |
| HTML | 9 | 0.47 | 9049 | 0.93 | 2564 | 0.97 | 387 | 0.65 |
| R | 8 | 0.42 | 575 | 0.06 | 38 | 0.01 | 122 | 0.21 |
| Rmd | 2 | 0.11 | 117 | 0.01 | 45 | 0.02 | 85 | 0.14 |
## Code of Conduct


+ 607
- 0
data-raw/2020-01-14-us-elections-debate-speaking-time.html
File diff suppressed because it is too large
View File


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

@ -24,6 +24,7 @@ if (!file.exists(here::here("data-raw/2019-09-12-us-elections-debate-speaking-ti
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"))
if (!file.exists(here::here("data-raw/2020-01-14-us-elections-debate-speaking-time.html"))) download.file("https://www.nytimes.com/interactive/2020/01/14/us/politics/debate-speaking-time.html", here::here("data-raw/2020-01-14-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')]") %>%
@ -354,7 +355,6 @@ 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() %>%
@ -412,6 +412,67 @@ read_html(here::here("data-raw/2019-12-19-us-elections-debate-speaking-time.html
) %>%
as_tibble() -> dec_day_1
read_html(here::here("data-raw/2020-01-14-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("2020-01-14"),
speaker = stri_trans_totitle(speaker),
timestamp = parse_time(timestamp),
debate_group = 7,
night = 1
) %>%
filter(speaker != "") %>%
mutate(
topic = case_when(
topic == "" ~ "Other",
grepl("military", topic) ~ "Military",
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("child-care", topic) ~ "Child Care",
grepl("health-care", topic) ~ "Healthcare",
grepl("immigration", topic) ~ "Immigration",
grepl("impeachment", topic) ~ "Impeachment",
grepl("income-inequality", topic) ~ "Income Inequality",
grepl("female-president", topic) ~ "Female President",
grepl("trade", topic) ~ "Trade",
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() -> jan_20_day_1
bind_rows(
jun_day_1,
jun_day_2,
@ -420,7 +481,8 @@ bind_rows(
sep_day_1,
oct_day_1,
nov_day_1,
dec_day_1
dec_day_1,
jan_20_day_1
) %>%
mutate(topic = case_when(
grepl("elect.*form", topic, ignore.case = TRUE) ~ "Election Reform",


BIN
data/debates2019.rda View File


Loading…
Cancel
Save