This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # OECD weekly all cause deaths to mortality rates | |
| # Keep in mind, some countries (Sweden) exclude 3% of deaths from the weekly | |
| # dataset as the day of death is not known | |
| library(OECD) | |
| library(dplyr) | |
| country1 = "NZL" | |
| country2 = "USA" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # MoH is the ministry of Health all cases demographics csv file | |
| # https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-case-demographics#case-details | |
| library(readr) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(ggthemes) | |
| library(lubridate) | |
| # you need to provide csv name | |
| file_name <- "covid_cases_2021-09-14.csv" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| davidise_graph <- function(x, savepath="~/Desktop/output", show_graph = TRUE){ | |
| # x is an unthemed ggplot graph but all the scales & labs are applied | |
| # since this function wants a ggplot graph, I am assuming ggplot is loaded) | |
| # assume Open Sans installed as a font | |
| library(showtext) | |
| # sort out your own font path declarations | |
| font_add(family = "OpenSans", regular = "~/Library/Fonts/OpenSans-Light.ttf", | |
| bolditalic = "~/Library/Fonts/OpenSans-BoldItalic.ttf", | |
| italic = "~/Library/Fonts/OpenSans-LightItalic.ttf", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Data | |
| # https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-case-demographics#case-details | |
| library(readr) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(ggthemes) | |
| library(lubridate) | |
| library(patchwork) | |
| # you need to provide csv name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rtweet) | |
| library(dplyr) | |
| library(lubridate) | |
| library(ggplot2) | |
| library(tidytext) | |
| library(topicmodels) | |
| search_term <- "#nzpol" | |
| corpus <- search_tweets(search_term, n=18000) | |
| nzpol_utm <- corpus %>% select(screen_name, text) %>% | |
| unnest_tokens(word,text, token="tweets") %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readr) | |
| library(suncalc) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(ggthemes) | |
| library(lubridate) | |
| library(tidyr) | |
| quake10yr <- c("https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2020-02-01&enddate=2021-03-01T0:00:00", | |
| "https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2019-02-01&enddate=2020-02-01", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rvest) | |
| target_url <- "https://www.publicservice.govt.nz/resources/proactive-releases/" | |
| webpage <- target_url %>% read_html() | |
| links <- webpage %>% html_nodes("a") %>% html_attr("href") | |
| link_text <- webpage %>% html_nodes("a") %>% html_text() | |
| link_set <- data.frame(links, link_text, stringsAsFactors = FALSE) | |
| if(file.exists("linkcurrent.csv")){ | |
| linkcurrent <- read.csv("linkcurrent.csv", stringsAsFactors = FALSE) | |
| newlinks <- link_set[!link_set$links %in% linkcurrent$links,] | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # works through | |
| # https://www.health.govt.nz/news-media/media-releases?page=1 and subsequent pages | |
| library(rvest) | |
| library(dplyr) | |
| library(stringr) | |
| table_fetch <- function(x){ | |
| url_loc <- paste0("https://www.health.govt.nz",x) | |
| page_obj <- url_loc %>% read_html() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readr) | |
| library(suncalc) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(ggthemes) | |
| library(lubridate) | |
| library(tidyr) | |
| quake10yr <- c("https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2020-02-01&enddate=2021-03-01T0:00:00", | |
| "https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2019-02-01&enddate=2020-02-01", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############ collection | |
| ## assumes the working directory is the folder the script is in, and is set to the same for future runs of the file. | |
| # This also assumes you have twitter developer credientals, and have run the create_token() function in the rtweet package | |
| # to authorise r to access Twitter. This stores the credentials in an environmental variable loaded at startup so they are | |
| # not exposed in the script | |
| # as an alternative, if using a Mac or PC, and the httpuv package is installed, you can interactively authorise the script | |
| # at run time | |
| # these packages need to be already installed in order to be loaded and used |