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
# remotes::install_github("rvlenth/emmeans") | |
# use the latest version of emmeans, as the current cran version 1.5.4 containsa bug | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(lme4) | |
library(emmeans) | |
# create fits function: | |
create_fit <- function(x, variant = "nv1",n = 100){ |
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(gganimate) | |
# needs packages gifski & transformr | |
# If they are not installed, please also run | |
# install.packages(c("gifski", "transformr")) | |
# Function that does the simulation | |
create_pvals <- function(n){ | |
x <- rnorm(n) | |
y <- rnorm(n) | |
last <- seq(10,n,by=10) |
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
# Plot UAH monthly temperatures | |
# Joris Meys | |
# Date last modified: 2019-11-18 | |
# Create a temporary filename | |
fname <- tempfile() | |
# Download data into the temporary file | |
download.file("https://www.nsstc.uah.edu/data/msu/v6.0/tlt/uahncdc_lt_6.0.txt",destfile = fname) |
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(shiny) | |
# Define server logic required to draw a histogram | |
shinyServer(function(input, output) { | |
mysamples <- reactive({ | |
fdist <- switch(input$dist, | |
Normal = rnorm, | |
Exponential = rexp, | |
Poisson = function(n) rpois(n,4)) |
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
## ----setup, include=FALSE------------------------------------------------ | |
knitr::opts_chunk$set(echo = TRUE) | |
# Needed so the code runs later on. | |
datadir <- "pottmp_data" | |
fnames <- paste("pottmp",1980:2019,"nc", sep = ".") | |
## ----Download information, eval=FALSE------------------------------------ | |
## # ONLY RUN THIS ONCE TO DOWNLOAD THE DATA | |
## # This downloads 39 files of appx 144 Mb each! | |
## # Create a directory to store the data. |
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
# Download median of regional timeseries | |
temp <- readLines("https://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.6.0.0.monthly_ns_avg.txt") | |
temp <- data.frame(do.call(rbind, strsplit(temp," ")), | |
stringsAsFactors = FALSE) | |
temp[-1] <- lapply(temp[-1], as.numeric) | |
temp$year <- as.numeric(gsub("/.*","",temp[,1])) | |
temp$month <- as.numeric(gsub(".*/","",temp[,1])) | |
temp$time <- temp$year + temp$month/12.5 |
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(tidyr) | |
library(ggplot2) | |
# I look at 4 different rates here. The rate for the period 2000-2018 was approximately 3 mm / year. | |
rates <- c(0.15,0.2,0.3, 0.4) | |
# This creates a tibble (dataset) with the sea level rise until 2100 depending on the rate | |
mydata <- tibble( | |
years = seq(2018,2100, by=1), | |
slow = seq_along(years)*rates[1], |
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
``` r | |
library(magrittr) | |
library(purrr) | |
#> | |
#> Attaching package: 'purrr' | |
#> The following object is masked from 'package:magrittr': | |
#> | |
#> set_names | |
library(microbenchmark) |
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
# Currently roxygen 6.1.0 doesn't read the collate field correctly, so once you use @include anywhere | |
# in your package, you run into problems. The error you get, is a 'Permission denied' error. If that | |
# occurs, best thing to do for now is to install the previous version of roxygen until | |
# the problem is solved. | |
# | |
# I've made a binary build for Windows available. You can download it manually from following link: | |
# https://jorismeys.stackstorage.com/s/co8cKzyRemVHZef | |
# Alas the filesharing I use doesn't allow automatic downloading through download.file(), so you | |
# have to go to that link and click on Download to get the actual zip file. | |
# |
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(OECD) | |
library(dplyr) | |
library(ggplot2) | |
## Get the latest OECD data on decile ratios of gross earnings. | |
## This is the dataset that contains information on wage gaps. | |
oecdData <- get_dataset("DEC_I") | |
## Prepare the plot data | |
gwg <- |
NewerOlder