-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscript_2019-11-12.R
57 lines (45 loc) · 1.73 KB
/
script_2019-11-12.R
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
library(ggchicklet)
library(fishualize)
library(tidyverse)
library(grid)
#### Data ####
cran_code <- read_csv("data/data_2019-11-12.csv", col_types = "dcdddcc")
#### Table ####
df_characters <-
cran_code %>%
pull(pkg_name) %>%
unique() %>%
str_split(pattern = "") %>%
unlist() %>%
table() %>%
enframe(name = "alphanum", value = "count") %>%
mutate(
count = as.numeric(count),
type = case_when(alphanum == "." ~ "dot",
alphanum %in% 0:9 ~ "digits",
TRUE ~ "letters"),
family = case_when(
alphanum %in% c("r", "R") ~ "R",
type == "letters" & alphanum == str_to_lower(alphanum) ~ "lower",
type == "letters" & alphanum == str_to_upper(alphanum) ~ "upper",
TRUE ~ type),
type = fct_relevel(type, "dot"),
family = fct_relevel(family, "R"))
#### Plot ####
ggplot(df_characters) +
aes(x = alphanum, y = count, fill = family) +
geom_chicklet(radius = unit(2, "pt")) +
geom_text(aes(label = alphanum), vjust = -0.2, family = "Akbar", size = 4) +
geom_text(x = 42, y = 8600, family = "Akbar", size = 8,
label = "Character counts in R packages names") +
labs(caption = "Source: CRAN\n@_abichat for #TidyTuesday") +
scale_fill_fish_d(option = "Scarus_quoyi") +
scale_y_continuous(breaks = 1:4 * 2000, sec.axis = dup_axis()) +
theme_minimal() +
theme(panel.grid.major.x = element_blank(),
legend.position = "none",
axis.title = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_text(family = "Akbar"),
plot.caption = element_text(family = "Akbar", vjust = 6, size = 10))
ggsave("plots/plot_2019-11-12.png", width = 29, height = 11.5, units = "cm", dpi = "retina")