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(move2) | |
library(ritis) | |
library(sf) | |
library(tidyverse) | |
# Download movebank study-level information | |
movebank_studies <- movebank_download_study_info( | |
# Filter to studies where data are *visible* (not necessarily downloadable) | |
i_can_see_data = TRUE, | |
# Specify the list of attributes we want to query |
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(tidyverse) | |
set.seed(123) | |
ex_countries <- tibble( | |
country = c("Canada", "USA", "Mexico", "Brazil", "Chile"), | |
ruleoflaw = c(0.8, 0.7, 0.41, 0.5, 0.66), | |
ruleoflawZ = (ruleoflaw - mean(ruleoflaw)) / sd(ruleoflaw) | |
) | |
sharks <- tibble( | |
commonname = c("Tiger", "Bull", "Blacktip", "Nurse"), |
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
# Make the whole analysis | |
# The prequisite for all is the end of your pipeline (in this case, your model predictions) | |
.PHONY: all | |
all: models/predictions.pkl | |
# You can preview the sequence of commands in the pipeline with: make all -B --recon | |
# I recommend putting that in your README | |
# 1. Download raw data | |
### replace species.csv, species2.csv, etc with names of your raw data files | |
### the ampersand-colon &: tells make that this rule has multiple grouped targets |
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
# Based on tutorial: https://gganimate.com/articles/gganimate.html | |
# Accessed 2021-10-01 | |
library(gganimate) | |
# We'll start with a static plot | |
p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + | |
geom_point() | |
plot(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
# If you don't have devtools, install that first. If you have Windows and R version 4.0 (or greater), see: https://cran.r-project.org/bin/windows/Rtools/ | |
devtools::install_github("lockedata/datasauRus") | |
# Load the datasaurus dozen and our favorite suite of data processing tools | |
library(datasauRus) | |
library(tidyverse) | |
# Quick look at the contents of the datasaurus_dozen data frame | |
summary(datasaurus_dozen) | |
unique(datasaurus_dozen$dataset) |
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(geosphere) | |
library(glue) | |
library(ggplot2) | |
library(mapproj) | |
# Example data frame | |
set.seed(1) | |
tracks <- tibble( | |
time = 1:5, |
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
pred_mr <- function( | |
mass_kg, | |
mr_method = c("kleiber", "kolokotronesetal", "nagy", "savageetal", "whiteseymour"), | |
unit = c("kcal_day", "kJ_day", "mlO2_hr", "W"), | |
multiplier = 1 | |
) { | |
#' Predicted metabolic rate | |
#' | |
#' Predict mammalian metabolic rates from various scaling equations. | |
#' |
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(ggrepel) | |
library(tidyverse) | |
# These were my measurements for mussel area and quadrat area respectively | |
musselfrac <- 0.043 / 0.097 | |
# dbinom() is the probability of n successes out of x trials with probability p | |
# So dbinom(0:25, 25, musselfrac) is the chance of: [0 points in mussels, 1 | |
# point in mussels, 2 points in mussels, ..., 25 points in mussels] | |
musselprobs <- tibble(n = 0:25, | |
p = dbinom(0:25, 25, musselfrac)) | |
# This is the probability of 24/25 points in mussels |
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(tidyverse) | |
# Start with some dummy data | |
whale_data <- tribble( | |
~species, ~prey, ~order, | |
"B. musculus", "krill", 5, | |
"B. physalus", "fish", 3, | |
"B. physalus", "krill", 4, | |
"M. novaeangliae", "fish", 1, | |
"M. novaeangliae", "krill", 2 |
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(raster) | |
library(scales) | |
library(tidyverse) | |
powpow <- function(n, a, b) { | |
# based on answers at: https://dsp.stackexchange.com/questions/47640/generating-a-timeseries-with-an-arbitrary-power-spectrum | |
# Thank you Sam! | |
if (n %% 2 != 0) |
NewerOlder