Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntoineSoetewey/c6e83ad501a4b8c12b32cf9d5c06e9f9 to your computer and use it in GitHub Desktop.
Save AntoineSoetewey/c6e83ad501a4b8c12b32cf9d5c06e9f9 to your computer and use it in GitHub Desktop.
How to create a timeline of your CV in R. See more information at: https://statsandr.com/blog/how-to-create-a-timeline-of-your-cv-in-r/
# All packages used below must be installed first
library(devtools)
# devtools::install_github("laresbernardo/lares")
library(lares)
library(ggplot2)
today <- as.character(Sys.Date())
### Edit from here ###
cv <- data.frame(rbind(
c("PhD in Statistics", "University3", "Academic", "2017-09-01", today),
c("MSc in Econometrics", "University2", "Academic", "2015-09-01", "2017-08-31"),
c("BSc in Economics", "University1", "Academic", "2010-09-01", "2013-08-31"),
c("Job title2", "Company2", "Work Experience", "2016-09-01", today),
c("Job title1", "Company1", "Work Experience", "2013-08-31", "2015-08-31"),
c("Extra1", "Place1", "Extra", "2015-05-01", today),
c("Extra2", "Place2", "Extra", "2019-01-01", today),
c("Extra3", NA, "Extra", "2019-12-01", today)
))
### Edit until here ###
order <- c("Role", "Place", "Type", "Start", "End")
colnames(cv) <- order
plot_timeline2 <- function(event, start, end = start + 1, label = NA, group = NA,
title = "Curriculum Vitae Timeline", subtitle = "Antoine Soetewey",
size = 7, colour = "orange", save = FALSE, subdir = NA) {
df <- data.frame(
Role = as.character(event), Place = as.character(label),
Start = lubridate::date(start), End = lubridate::date(end),
Type = group
)
cvlong <- data.frame(pos = rep(
as.numeric(rownames(df)),
2
), name = rep(as.character(df$Role), 2), type = rep(factor(df$Type,
ordered = TRUE
), 2), where = rep(
as.character(df$Place),
2
), value = c(df$Start, df$End), label_pos = rep(df$Start +
floor((df$End - df$Start) / 2), 2))
maxdate <- max(df$End)
p <- ggplot(cvlong, aes(
x = value, y = reorder(name, -pos),
label = where, group = pos
)) + geom_vline(
xintercept = maxdate,
alpha = 0.8, linetype = "dotted"
) + labs(
title = title,
subtitle = subtitle, x = NULL, y = NULL, colour = NULL
) +
theme_minimal() + theme(panel.background = element_rect(
fill = "white",
colour = NA
), axis.ticks = element_blank(), panel.grid.major.x = element_line(
size = 0.25,
colour = "grey80"
))
if (!is.na(cvlong$type)[1] | length(unique(cvlong$type)) >
1) {
p <- p + geom_line(aes(color = type), size = size) +
facet_grid(type ~ ., scales = "free", space = "free") +
guides(colour = "none") +
scale_colour_manual(values = c("#F8766D", "#00BA38", "#619CFF")) +
theme(strip.text.y = element_text(size = 10))
}
else {
p <- p + geom_line(size = size)
}
p <- p + geom_label(aes(x = label_pos),
colour = "black",
size = 2, alpha = 0.7
)
if (save) {
file_name <- "cv_timeline.png"
if (!is.na(subdir)) {
dir.create(file.path(getwd(), subdir), recursive = T)
file_name <- paste(subdir, file_name, sep = "/")
}
p <- p + ggsave(file_name, width = 8, height = 6)
message(paste("Saved plot as", file_name))
}
return(p)
}
plot_timeline2(
event = cv$Role,
start = cv$Start,
end = cv$End,
label = cv$Place,
group = cv$Type,
save = FALSE,
subtitle = "Antoine Soetewey" # replace with your name
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment