Skip to content

Instantly share code, notes, and snippets.

@Torvaney
Created June 12, 2018 12:20
Show Gist options
  • Save Torvaney/f9ce0c388cf05e6447d605976e1e984c to your computer and use it in GitHub Desktop.
Save Torvaney/f9ce0c388cf05e6447d605976e1e984c to your computer and use it in GitHub Desktop.
library(tidyverse)
library(lubridate)
source("https://raw.githubusercontent.com/mjfrigaard/RDataSets/master/DotR/monarchs.R")
monarchs <-
monarchs %>%
mutate(reign_length = lubridate::interval(from, to) / years(1))
monarchs %>%
ggplot() +
geom_segment(aes(x = from, y = 0,
xend = to, yend = reign_length)) +
geom_point(aes(x = to, y = reign_length))
monarchs %>%
ggplot(aes(x = reign_length)) +
geom_histogram() +
stat_function(fun = function(x, lambda, total) {
lambda * exp(-lambda * x) * total
}, args = c(lambda = 1 / mean(monarchs$reign_length, na.rm = T),
total = 200))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment