This file contains 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
.bubbles { | |
stroke-width: 1px; | |
stroke: black; | |
opacity: .8 | |
} | |
.bubbles:hover { | |
stroke: black; | |
} | |
* { |
This file contains 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
sf_arrow <- function(from, to, len, deg, prefixFrom='from.', prefixTo='to.') { | |
# from, to: sf objects. `from` should be either a single point, or the same | |
# number of points as in `to`. | |
# len: the length of the arrow head, in map units. | |
# deg: the angle (in degrees) of the arrow head. | |
# prefixFrom, prefixTo: the attributes of `from` and `to` are added to the | |
# returned sf object. These prefixes will be prepended to the existing names | |
# of `from` and `to`. | |
crs <- st_crs(to) | |
n <- nrow(to) |
This file contains 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(dplyr) | |
library(jsonlite) | |
# create an empty list to store results | |
items <- list() | |
i <- 1 # initialise counter to 1. This is used to specify the start index for queries | |
# We can download at most 100 records at a time, so we download in pages, | |
# increasing the start index by 100 each time. We do this until the result of | |
# the query has fewer than 100 results (i.e. we've retrieved the last page of |
This file contains 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
dms2dd <- function(x) { | |
dms <- strsplit(x, '[^0-9.]+') | |
sapply(dms, function(x) { | |
sum(as.numeric(x)/c(1, 60, 3600)[seq_along(x)]) | |
}) | |
} | |
dms2dd(c('34°53’07”S', '138°36’40”E', '138.61111', '34°53’')) | |
## [1] 34.88528 138.61111 138.61111 34.88333 |
This file contains 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
process_hysplit_sims <- function(file) { | |
require(dplyr) | |
require(sf) | |
dat <- readLines(file) | |
starts <- grep('PRESSURE', dat) + 1 | |
ends <- grep('New Simulation', dat) - 2 | |
ends <- c(ends[ends > starts[1]], length(dat)) | |
combined <- mapply(function(s, e, i) { | |
read.fwf(file=textConnection(dat[s:e]), | |
widths=c(6,6,6,6,6,6,6,6,8,9,9,9,9)) |
This file contains 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
collapse_numeric <- function(index) { | |
# index: path to home page of bookdown-generated HTML book (e.g. index.html) | |
doc <- readLines(index) | |
pages <- file.path( | |
dirname(index), sub('.*data-path="(.*?)".*', '\\1', | |
grep('data-level="\\d+"', doc, val=T)) | |
) | |
lapply(pages, function(p) { | |
x <- rmarkdown:::read_utf8(p) |
This file contains 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(jsonlite) | |
library(xml2) | |
library(rvest) | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(plotly) | |
d <- xml2::read_html('https://public.flourish.studio/visualisation/1619458/embed') | |
js <- rvest::xml_nodes(d, 'script') %>% html_text |
This file contains 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
doi2bib <- function(dois, file=NULL, quiet=FALSE) { | |
# dois: vector of dois | |
require(httr) | |
bibs <- sapply(dois, function(x) { | |
if(!quiet) message(x) | |
response <- httr::GET( | |
'http://dx.doi.org', path=x, | |
add_headers(Accept = 'application/x-bibtex') | |
) | |
httr::content(response, as='text', encoding='UTF-8') |
This file contains 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
# See https://stackoverflow.com/q/59851541/489704 | |
fix_limits <- function(p) { | |
if(!is.numeric(p$panel.args.common$breaks)) | |
stop('trellis object should be constructed specifying nint') | |
b <- p$panel.args.common$breaks | |
pad <- diff(b[1:2]) | |
lims <- lapply(p$panel.args, function(x) { | |
bins <- findInterval(x$x, b) | |
ymax <- max(unlist(tapply(bins, p$panel.args.common$groups[x$subscripts], | |
function(y) table(y)/length(y)))) + 0.025 |
NewerOlder