library(data.table)
library(ggplot2)
library(metR)
out.file <- "~/Downloads/erebus_atm_2001_dem_v5.tif"
if (!file.exists(out.file)) {
# data => https://www.pgc.umn.edu/data/elevation/
# ~ 90Mb
download.file("http://data.pgc.umn.edu/elev/dem/atm/2001/erebus_atm_2001_dem_v5.tif",
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(ggplot2) | |
library(data.table) | |
# Datos de este link: http://midcdmz.nrel.gov/apps/plot.pl?site=NWTC&start=20010824&edy=26&emo=3&eyr=2062&year=2013&month=1&day=1&endyear=2013&endmonth=12&endday=31&time=0&inst=21&inst=39&type=data&wrlevel=2&preset=0&first=3&math=0&second=-1&value=0.0&user=0&axis=1 | |
wind <- fread("~/Downloads/20130101.csv") | |
# La función cut me da los intervalos en orden decresciente, pero | |
# los necesito en orden cresciente. | |
ReverseCut <- function(x, ...) { | |
f <- cut(x, ...) |
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
--- | |
title: "Untitled" | |
author: "Elio" | |
output: | |
pdf_document: | |
keep_tex: yes | |
fig_caption: yes | |
header-includes: | |
- \usepackage{subfig} | |
--- |
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
# a <- 6371000 | |
lonlat2xy <- function(lon, lat, a = 6371000) { | |
A <- pi/2*a*(1 - lat/90) | |
rot <- 0 | |
x <- cos((lon + rot)*pi/180)*A | |
y <- sin((lon + rot)*pi/180)*A | |
return(list(x = x, y = y)) | |
} |
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(ggplot2) | |
df <- data.frame(x = rnorm(100), y = rnorm(100)) | |
df$dir <- with(df, atan2(y, x)) | |
df$t <- 1:nrow(df) | |
## The default is, of course, ridiculous. | |
(g <- ggplot(df, aes(dir, t)) + | |
geom_point(aes(color = dir)) + |
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(data.table) | |
library(ggplot2) | |
data(volcano) | |
volcano <- as.data.table(melt(volcano, varnames = c("x", "y"), | |
value.name = "h")) | |
volcano[, c("dx", "dy") := metR::Derivate(h ~ x + y)] # from my package. It calculates directional derivatives. | |
volcano[, angle := atan2(-dy, -dx)] |
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
geom_relief <- function(mapping = NULL, data = NULL, | |
stat = "identity", position = "identity", | |
..., | |
raster = TRUE, | |
interpolate = TRUE, | |
na.rm = FALSE, | |
show.legend = NA, | |
inherit.aes = TRUE) { | |
ggplot2::layer( | |
data = data, |
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
notify <- function(title = "title", text = NULL, time = 2) { | |
time <- time*1000 | |
system(paste0("notify-send ", title, " ", text, "-t ", time, " -a rstudio")) | |
} | |
notify_after <- function(expression, ...) { | |
expression <- eval(expression) | |
notify(title = "Run\\ ended", ...) | |
return(expression) | |
} |
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(ggplot2) | |
url <- "https://ih0.redbubble.net/image.512523322.6908/flat,800x800,075,f.jpg" | |
file <- tempfile() | |
download.file(url, file) | |
im <- jpeg::readJPEG(file) | |
im <- apply(im, c(1, 2), sum) | |
im <- im/3 | |
ys <- nrow(im) | |
xs <- ncol(im) |
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
geom_relief <- function(mapping = NULL, data = NULL, | |
stat = "identity", position = "identity", | |
..., | |
anglebreaks = 60, | |
sunangle = 60, | |
shadow = TRUE, | |
maxsearch = 100, | |
lambert = TRUE, | |
zscale = 1, | |
multicore = TRUE, |
OlderNewer