Basically, we need to count the hashtag for every year. Since the hashtags for a particular year is in single-column we need to separate it into different columns and then we can convert the df into a long df, where it becomes possible for us to group it based on year and hashtag to find the count.
library(tidyverse)
structure(list(terms = c("#A;#B;#C", "#B;#C;#D", "#C;#D;#E",
"#D;#E;#F", "#E;#F;#G", "#F;#G;#H", "#G;#H;#I", "#H;#I;#J", "#I;#J;#K",
"#J;#K;#L"), year = c(2017, 2016, 2021, 2020, 2020, 2020, 2019,
2018, 2020, 2020)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame")) -> df
df %>%
separate(terms, into = paste0("t", 1:3), sep = ";") %>%
pivot_longer(-year) %>%
group_by(year, value) %>%
count(value) %>%
ggplot(aes(x = year, y = n, fill = value, label = n)) +
geom_col(position = position_dodge()) +
geom_text(position = position_dodge(1))
Created on 2021-02-05 by the reprex package (v0.3.0)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…