问题
分析
数据:来自@小灰侠整理,https://blog.csdn.net/coding_Joash/article/details/120579109
(白嫖使我快乐)
library(org.Hs.eg.db)
### gene id 以及对应的发表时间
gene <- read_tsv("Homo_GeneID_year.txt", col_types = cols("c", "c"))
###得到gene id对应得gene symbol
ids=toTable(org.Hs.egSYMBOL)
HS_GENE_YEAR <- inner_join(ids, gene, by=c('gene_id' = "GeneID"))
### 绘制词云图函数
### 可绘制gene symbol ,也可绘制year
plotWC <- function(keys, key_type = "year", size=0.4, shape='star'){
if (key_type == "year"){
gene_freq <- HS_GENE_YEAR %>%
filter(year %in% keys) %>%
group_by(symbol) %>%
summarise(freq=n())
wordcloud2::wordcloud2(gene_freq, size = size,shape = shape)
}else if(key_type == "gene"){
year_freq <- HS_GENE_YEAR %>%
filter(symbol %in% keys) %>%
group_by(year) %>%
summarise(freq=n())
wordcloud2::wordcloud2(year_freq, size = size, shape = shape)
}
}
### 绘制柱状图
plot_bar <- function(genes, years=NULL){
if (is.null(years)){
years <- HS_GENE_YEAR$year
}
data <- HS_GENE_YEAR %>%
filter(symbol %in% genes) %>%
filter(year %in% years) %>%
group_by(year) %>%
count(symbol) %>%
ungroup()
ggplot(data) +
geom_bar(aes(x=year, y=n, fill=symbol),
position = "dodge", stat = "identity")
}
绘制2000-2021 得基因符号词云图:
plotWC(keys = 2000:2021)
绘制TP53 发表年限词云图
plotWC(keys = c("TP53"), key="gene")
查看"APOE", “EGFR”, “ACE”, 2000-2021 发表文章数
genes <- c("APOE", "EGFR", "ACE")
plot_bar(genes, 2000:2021)