task4a_TCGA_Pan_Cancer

把tcga大计划的CNS级别文章标题画一个词云

方式1

给自己的浏览器装个XPATH
点击XPATH
XPATH
然后写入://*/div[1]/div/div/div/div/ul/li[2]/a
TCGA_xpath
直接复制右边的33篇文章标题,存为TCGA_33_title.txt即可

方式2

打开网页:https://www.cell.com/pb-assets/consortium/pancanceratlas/pancani3/index.html
右键点击网页另存
然后用task4b_Nature_PAN_Cancer_词云
里面同样的方法解析网页即可

urlpage <- XML::htmlParse('Welcome to the Pan-Cancer Atlas.html') #解析xml
title = XML::xpathSApply(urlpage, '//*/div[1]/div/div/div/div/ul/li[2]/a') 
title=lapply(title, function(name){name[[1]]})
title

sink("TCGA_33_title.txt")
for (data in title) {
  print(data)
  #产生了一个特殊空格<U+00A0>,这个是空格的特殊格式;使用特殊字符进行表达\u00A0$
}
sink()
file <- scan('TCGA_33_title.txt',sep='\n',what='',encoding="UTF-8")
txtList = lapply(file, strsplit,"\\s+") #使用空格符号进行分词
txtChar = tolower(unlist(txtList)) #把所有单词变为小写模式
txtChar <- txtChar[nchar(txtChar)>2] #去除字符长度小于2的词语
txtChar <- table(txtChar) #统计词频
#grepl类似grep,但是返回逻辑向量,即是否包含pattern
txtChar <- txtChar[!grepl('^[0-9-,]+$',names(txtChar),perl = TRUE)] #去除纯数字
txtChar <- txtChar[!grepl('^and|the|of$',names(txtChar),perl = TRUE)] #delete and the,of
data=data.frame(txtChar)

wordcloud::wordcloud(words = data$txtChar, freq = data$Freq, min.freq = 1,
                     max.words=200, random.order=FALSE, rot.per=0.35, 
                     colors=RColorBrewer::brewer.pal(8, "Dark2"))

TCGA_33_title_词云

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值