hltb-stats.r
· 1.4 KiB · R
Orginalformat
library(ggplot2)
library(readr)
library(tidyr) # pivot_longer
library(ggbreak) # data break point
library(scales) # custom trans
data <- read_csv("1.csv", col_types = cols(
Lastmod = col_date(format = "%Y-%m-%d"),
.default = col_integer() # cool import
))
# use custom trans to multiply DP 50- to 5x
# as DP 2000+ occpies too much space in y axis
custom_trans <- trans_new(
name = "custom",
transform = function(x) ifelse(x < 50, x * 5, x), # if 50-, 5x
# "Retired" starts at 400, so we are safe here
inverse = function(x) ifelse(x < 250, x / 5, x) # if 250-, 1/5
)
# simplify data to avoid redundant lines
data_long <- data %>%
pivot_longer(cols = -Lastmod, names_to = "Tag", values_to = "Count")
p <- ggplot(data_long, aes(x = Lastmod, y = Count, color = Tag)) +
geom_line(alpha = 0.8) +
geom_point() +
scale_color_manual(values = c(
"Playing" = "#2f933a", "Backlogs" = "#2b7ab9", "Replays" = "#439de3",
"Stalled" = "#1b7168", "Completed" = "#934b93", "Retired" = "#cb3a3b"
)) + # HLTB style
scale_y_continuous(trans = custom_trans) + # apply custom trans
scale_y_break(c(40, 380)) + # skip gap in y axis
scale_y_break(c(700, 2500)) +
labs(title = "HLTB Trend 2024", x = "Date", y = "Count", color = "Tag") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggsave("hltb-trend-2024.png", plot = p, width = 10, height = 6, dpi = 300)
1 | library(ggplot2) |
2 | library(readr) |
3 | library(tidyr) # pivot_longer |
4 | library(ggbreak) # data break point |
5 | library(scales) # custom trans |
6 | |
7 | data <- read_csv("1.csv", col_types = cols( |
8 | Lastmod = col_date(format = "%Y-%m-%d"), |
9 | .default = col_integer() # cool import |
10 | )) |
11 | |
12 | # use custom trans to multiply DP 50- to 5x |
13 | # as DP 2000+ occpies too much space in y axis |
14 | custom_trans <- trans_new( |
15 | name = "custom", |
16 | transform = function(x) ifelse(x < 50, x * 5, x), # if 50-, 5x |
17 | # "Retired" starts at 400, so we are safe here |
18 | inverse = function(x) ifelse(x < 250, x / 5, x) # if 250-, 1/5 |
19 | ) |
20 | |
21 | # simplify data to avoid redundant lines |
22 | data_long <- data %>% |
23 | pivot_longer(cols = -Lastmod, names_to = "Tag", values_to = "Count") |
24 | |
25 | p <- ggplot(data_long, aes(x = Lastmod, y = Count, color = Tag)) + |
26 | geom_line(alpha = 0.8) + |
27 | geom_point() + |
28 | scale_color_manual(values = c( |
29 | "Playing" = "#2f933a", "Backlogs" = "#2b7ab9", "Replays" = "#439de3", |
30 | "Stalled" = "#1b7168", "Completed" = "#934b93", "Retired" = "#cb3a3b" |
31 | )) + # HLTB style |
32 | scale_y_continuous(trans = custom_trans) + # apply custom trans |
33 | scale_y_break(c(40, 380)) + # skip gap in y axis |
34 | scale_y_break(c(700, 2500)) + |
35 | labs(title = "HLTB Trend 2024", x = "Date", y = "Count", color = "Tag") + |
36 | theme_minimal() + |
37 | theme(axis.text.x = element_text(angle = 45, hjust = 1)) |
38 | |
39 | ggsave("hltb-trend-2024.png", plot = p, width = 10, height = 6, dpi = 300) |