Skip to content

Instantly share code, notes, and snippets.

@samclifford
Created October 16, 2017 14:32
Show Gist options
  • Save samclifford/0a02d2087eb7b420567724ebbf989874 to your computer and use it in GitHub Desktop.
Save samclifford/0a02d2087eb7b420567724ebbf989874 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(magrittr)
library(purrr)
library(forcats)
base <- expand.grid(chem = c("Th", "Ta", "Nb", "La", "Ce", "P", "Zr", "Hf", "Sm", "Ti", "Y", "Yb", "Lu"),
id=1:7)
grouping <- data.frame(id=1:7,
trend=rep(c("WNW", "NE"),
times=c(2,5)))
dat <- inner_join(base, grouping)
dat %<>%
split( list(.$chem, .$trend)) %>%
map(~mutate(.x, mean = rlnorm(n=1))) %>%
map(~mutate(.x,
y = rlnorm(n=nrow(.x),
meanlog = .$mean,
sdlog = 0.1))) %>%
bind_rows %>%
mutate(chem = fct_inorder(chem)) %>%
arrange(chem, id)
ggplot(data=dat, aes(x=chem, y=y)) +
geom_line(aes(group=id, lty=trend)) +
scale_y_log10() +
theme_bw() +
annotation_logticks(sides="lr")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment