Skip to content

Instantly share code, notes, and snippets.

View nemochina2008's full-sized avatar

Nemochina2008 nemochina2008

  • P.R.China
View GitHub Profile
@nemochina2008
nemochina2008 / animate_accumulate_wbd.R
Created December 11, 2018 07:24 — forked from dblodgett-usgs/animate_accumulate_wbd.R
A visualization script to create frames of an animated gif of WBD accumulation where all paths terminate on the last time step.
# https://github.com/dblodgett-usgs/nhdplusTools
library(nhdplusTools)
# https://github.com/USGS-R/HUCAgg
library(HUCAgg)
library(sf)
library(dplyr)
library(snow)
wbd_gdb <- "WBD_National_GDB.gdb"
library(USAboundaries)
library(sf)
library(dplyr)
library(elevatr)
library(raster)
# Get map of lower 48 states
usa_l48 <- us_boundaries() %>%
filter(state_abbr != "HI" &
state_abbr != "AK" &
# Code from Richard McElreath's book, chapter 6
sppnames <- c( "afarensis","africanus","habilis","boisei",
"rudolfensis","ergaster","sapiens")
brainvolcc <- c( 438 , 452 , 612, 521, 752, 871, 1350 )
masskg <- c( 37.0 , 35.5 , 34.5 , 41.5 , 55.5 , 61.0 , 53.5 )
d <- data.frame( species=sppnames , brain=brainvolcc , mass=masskg )
## R code 6.2
m6.1 <- lm( brain ~ mass , data=d )
@nemochina2008
nemochina2008 / lmer_vs_inla_lmm.R
Created November 25, 2018 01:58 — forked from aghaynes/lmer_vs_inla_lmm.R
Compare variances from lmer and INLA for a linear mixed model (random intercept)
#
# Compare lmer and inla for LMM
# largely taken from Spatial and spatio-temporal bayesian models with R-INLA (Blangiardo & Cameletti, 2015), section 5.4.2
#
m <- 10000 # N obs
set.seed(1234)
x <- rnorm(m)
group <- sample(seq(1, 100), size = m, replace = TRUE)
---
title: "World maps"
output:
html_document:
df_print: paged
---
```{r echo = FALSE, message = FALSE}
library(tidyverse)
library(sf)
library(tidyverse)
library(lubridate)
library(broom)
library(scales)
library(gganimate)

# Load and clean data
# This data comes from Dark Sky's API
weather_provo_raw <- read_csv("https://andhs.co/provoweather")
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: [email protected]
### Twitter: @michaeljkoontz
###
@nemochina2008
nemochina2008 / themes.R
Created September 6, 2018 05:00 — forked from Pakillo/themes.R
ggplot_themes
### My favourite ggplot2 themes, always accessible ###
## just source this gist from any project ##
#####################################################################################
# Noam's default ggplot2 styling #####
# Source: https://github.com/noamross/noamtools/blob/master/R/theme_nr.R
theme_nr <-theme(text=element_text(family="Helvetica", size=14),
panel.grid.major.x=element_blank(),
@nemochina2008
nemochina2008 / fig_label.R
Created September 6, 2018 04:58 — forked from Pakillo/fig_label.R
R function to draw figure labels in base plots
## from: https://logfc.wordpress.com/2017/03/15/adding-figure-labels-a-b-c-in-the-top-left-corner-of-the-plotting-region/
fig_label <- function(text, region="figure", pos="topleft", cex=NULL, ...) {
region <- match.arg(region, c("figure", "plot", "device"))
pos <- match.arg(pos, c("topleft", "top", "topright",
"left", "center", "right",
"bottomleft", "bottom", "bottomright"))
if(region %in% c("figure", "device")) {
library(patchwork)
library(ggplot2)
library(purrr)
library(dplyr)
library(glue)
map(
5:8,
~iris %>%
filter(Petal.Length < .x) %>%
ggplot() +