Created
March 16, 2019 23:02
-
-
Save antagomir/1a9c80918e789be0f643dc0645ba02de to your computer and use it in GitHub Desktop.
Example timeline for reprints
This file contains hidden or 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
# reprints would be nodes; and edges would connect reprints of the same title? | |
set.seed(3452) | |
n <- 30 | |
year <- round(runif(n, min = 1600, max = 1800)) | |
publisher <- sample(1:3, n, replace = TRUE) | |
title <- c(rep("Bible", 10), rep("Bible2", n - 10)) | |
df <- data.frame(title = title, year = year, publisher = publisher) | |
df <- df %>% arrange(title, publisher, year) | |
minyear <- min(df$year, na.rm = TRUE) | |
edges <- NULL | |
for (tit in unique(df$title)) { | |
for (pub in unique(df$publisher)) { | |
dfs <- subset(df, publisher == pub & title == tit) | |
d <- data.frame(title = rep(tit, nrow(dfs)-1), | |
publisher = rep(pub, nrow(dfs)-1), | |
from = dfs$year[1:(nrow(dfs)-1)], | |
to = dfs$year[-1]) | |
edges <- rbind(edges, d) | |
} | |
} | |
edges$title <- factor(edges$title) | |
edges$publisher <- factor(edges$publisher) | |
d <- edges %>% filter(title == "Bible") | |
p <- ggplot(d) + | |
geom_line(aes(x = from, y = publisher)) + | |
geom_segment(aes(x = min(d$from), xend = max(d$to), y = publisher, yend = publisher)) + | |
geom_point(aes(x = d$from, y = publisher), size = 3) + | |
scale_x_reverse(breaks = d$from, labels = d$from) + | |
coord_flip() + | |
labs(x = "", y = "Publisher") | |
print(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment