-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline.Rmd
111 lines (96 loc) · 3.24 KB
/
timeline.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "R Notebook"
output: html_notebook
---
```{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("BA Sociology", "Winthrop University", "Academic", "2017-09-01", "2021-12-18"),
c("Data Analytics Program", "Thinkful", "Academic", "2022-06-01", today),
c("IT Team Lead", "TopGolf", "Work Experience", "2022-10-03", today),
c("Maintenance Technician", "TopGolf", "Work Experience", "2022-03-01", "2022-10-2"),
c("Time Using R", "R", "Extra", "2021-01-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 = "Bradford Johnson",
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_classic() +
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 = "Bradford Johnson" # replace with your name
)
```