-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupwards.R
More file actions
74 lines (68 loc) · 3.45 KB
/
upwards.R
File metadata and controls
74 lines (68 loc) · 3.45 KB
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
library(tidyverse)
library(extrafont)
library(ggtext)
# Get all file names that might have R code
all_files <- list.files(path = "~/", pattern ="\\.R$|.Rmd$", recursive = TRUE)
# Add the complete file
path_for_files <- paste0("~/", "\\/" ,all_files)
# Remove some files from paths that reference courses I downloaded/cloned
path_for_files <- path_for_files[!str_detect(path_for_files, "(Advanced-Research|my_PS6)")]
# Read lines
file_info <- map(path_for_files, file.info, extra_cols = TRUE)
# Add scripts as names
names(file_info) <- path_for_files
file_info_df <- map_dfr(file_info, ~ tibble(created = .x[["ctime"]]),
.id = "script") %>%
mutate(
# Split up to categories, more of a heuristic approach on the Author's end
category = case_when(
str_detect(script, "TidyTuesday") ~ "TidyTuesday",
str_detect(script, "amitlevinson.com|draft") ~ "Website",
str_detect(script, "30") ~ "Various\nchallenges",
str_detect(script, "Thesis|JO|CV") ~ "Thesis/ Work",
str_detect(script, "Courses|sql") ~ "Learning",
TRUE ~ "Other",
)
)
file_info_clean <- file_info_df %>%
arrange(created) %>%
# there's 1-2 files that have a very weird date.
filter(between(format(created,"%Y"), 2019, 2022)) %>%
add_count(script, category, created) %>%
group_by(category) %>%
mutate(cum_scripts = cumsum(n),
created = as.POSIXct(created, tz = "IDT")) %>%
ungroup()
group_labels <- file_info_clean %>%
group_by(category) %>%
filter(created == max(created)) %>%
mutate(vjust = ifelse(str_detect(category, "Various|Learning"), 1, 0.5))
ggplot(data = file_info_clean, aes(x = created, y= cum_scripts, color = category, group = category))+
geom_path(size =0.6)+
geom_point(data = group_labels,aes(x = created, y = cum_scripts), size = 0.8)+
geom_text(data = group_labels, aes(x = created, y = cum_scripts, label = category, vjust = vjust), hjust = -0.02, nudge_x = 3600*24*1, size =3.5, family = "Raleway Medium", lineheight = 0.8)+
coord_cartesian(clip = "off", expand = TRUE)+
guides(color = "none")+
scale_x_datetime(name = "Script creation date", breaks = "3 months", date_labels = "%b '%y", expand = c(0, 3600*24*60))+
scale_y_continuous(name = NULL, breaks = seq(0, 100, 20))+
labs(title = "My History of R Scripts",
subtitle = "Plot shows the creation history of R/Rmd scripts located on my computer: drafts, random<br>snippets and files uploaded to GitHub. Scripts are categorized to various subjects.<br><br><span style='color:gray25; font-size:11pt'>(Cumulative number of scripts)</span>",
caption = "Data: Personal Scripts | Viz: Amit_Levinson")+
theme_minimal()+
theme(
text = element_text(family = "Raleway"),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA),
plot.title.position = "plot",
plot.title = element_text(size = 23, family = "Bodoni MT"),
plot.subtitle = element_markdown(size = 12, color = "gray15"),
plot.caption = element_text(size = 9, color = "gray35", hjust = 1),
axis.title = element_text(color = "gray25", size = 11),
axis.title.y = element_text(angle = 0, hjust = 1, vjust = 0.5),
axis.text = element_text(color = "gray25", size = 10),
plot.margin = margin(5,3,3,5,"mm")
)
ggsave("code_and_plots/20_upwards/upwards.png", width = 11, height = 7)