Última atividade 1735984051

https://blog.vinfall.com/posts/2025/01/hltb-ggplot2/#end

Vinfall revisou este gist 1735984051. Ir para a revisão

1 file changed, 39 insertions

hltb-stats.r(arquivo criado)

@@ -0,0 +1,39 @@
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)
Próximo Anterior