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) | |
library(rethinking) | |
# khench implementation ------------------- | |
# updating funtion for an individual year | |
progress_year <- function(data, year, max_age = 65, n_births = 20, aom = 18){ | |
# initialize new cohort (new row for the population table) | |
new_cohort <- tibble( | |
age = 1, | |
married = as.integer(0), |
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) | |
data <- tibble(x = rnorm(50), | |
y1 = rnorm(50), | |
y2 = rnorm(50)+50, | |
y3 = rnorm(50) + 500) | |
p1 <- data |> | |
ggplot(aes(x = x)) + | |
geom_point(aes(y = y1)) + |
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) | |
library(lubridate) | |
s_col_names <- c("sample_id_idx", "Visit_no", "patch_id", "visit_duration", "exit_time", "entry_time", "Between_visit_duration", | |
"ID", "Species", "Patch_centroid_x", "Patch_centroid_y", "revisit_ID", "Time_since_last_visit", "trip_vedba", | |
"trip_vedba_mean", "total_patch_vedba", "mean_patch_vedba", "vedba_above_35", "vedba_below_35", "VID", | |
"Weight", "Sex", "Year", "week", "Study_day", "Week_year") | |
s_data <- read_csv("data/Revisits_BTH_edits_included.csv", | |
col_names = s_col_names,skip = 1) %>% | |
filter(Species == "Cebus capucinus") %>% |
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) | |
library(lubridate) | |
library(fuzzyjoin) | |
test_a <- tibble(gr = letters[rep(1:3,each = 5)], | |
timestamp = runif(15,min = 0,max = 10^8) %>% as_datetime()) | |
test_b <- tibble(year = rep(1970:1973, each = 2), | |
season = str_c(year,"_",rep(1:2, 4)), | |
season_start = str_c(year,rep(c("-01-01 00:00:00","-06-01 00:00:00"))) %>% as_datetime(), |
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) | |
library(prismatic) | |
d <- expand.grid(x = 1:25, y = 1:25) | |
bi_palette <- function(x, y, palette = viridis::viridis(5), dir_x = 1, dir_y = 1, y_fun = prismatic::clr_desaturate, limits_x = NULL, limits_y = NULL){ | |
stopifnot(length(x) == length(y)) | |
if(is.null(limits_x)){ limits_x <- range(x * dir_x, na.rm = TRUE) } | |
if(is.null(limits_y)){ limits_y <- range(y * dir_y, na.rm = TRUE) } | |
clr_1 <- scales::colour_ramp(palette)(scales::rescale(x * dir_x, from = limits_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
library(tidyverse) | |
library(patchwork) | |
pal <- 1 | |
walk_df <- tibble(x = seq(from = 0, to = 200, length.out = 15), | |
y = seq(from = 200, to = 0, length.out = 15)) %>% | |
mutate(val = map2_dbl(x,y, mirror_ratio)) | |
library(patchwork) | |
(walk_df %>% | |
ggplot(aes(x = x, y = val, color = val)) + |
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) | |
library(ggforce) | |
n <- 6 | |
tibble(t = seq(0, 2*pi,length.out = n+1)[0:(n+1)], | |
x = sin(t), y = cos(t), z = x + 1i * y) %>% | |
mutate(angle = Arg(z - lag(z)), | |
len = Mod(z - lag(z)), | |
shift_x = cos(angle) * len, | |
shift_y = sin(angle) * len) %>% |
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
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) |
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
# remotes::install_github("JoshOBrien/exiftoolr") | |
library(exiftoolr) | |
library(tidyverse) | |
ggplot(mtcars, aes(x = mpg, y = drat)) + geom_point() | |
ggsave("test.pdf") | |
ggsave("test.png") | |
message <- "created using the Rscript 'r_exiftool.R' by Kosmas Hench" |
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
network_layout <- function(n, rotate = 0, label = NULL, weight = 2, loc = NA){ | |
tau <- seq(0, 2*pi, length.out = n+1)[1:n] + rotate | |
nodes <- tibble::tibble(idx = 1:n, | |
x = sin(tau), | |
y = cos(tau)) | |
edges <- purrr::cross_df(tibble::tibble(pop1 = nodes$idx, | |
pop2 = nodes$idx), .filter = `>=`) %>% | |
dplyr::arrange(pop1) %>% | |
dplyr::left_join(., nodes %>% select(idx, x,y) %>% purrr::set_names(., nm = c('pop1','x','y'))) %>% |
NewerOlder