Created
June 12, 2018 12:20
-
-
Save Torvaney/f9ce0c388cf05e6447d605976e1e984c to your computer and use it in GitHub Desktop.
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) | |
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