【源码参考】R语言第二期2-4 统计某个研究领域的研究趋势

真·科研狗 2018-04-07 15:38:24 阅读: 553

以“p53”为例

library("httr")
countData = data.frame(year=c(), count = c())
url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"

for(i in 1:10){
  year=2007+i
  term = paste('(p53[TI]) AND ',year,'[DP]',sep = "")
  r <- POST(url, 
            body = list(
              db='pubmed',
              term=term,
              retmode='json',
              retstart=0,
              retmax=10,
              rettype='uilist'
            )
  )
  
  stop_for_status(r) #清除http状态字符串
  data=content(r, "parsed", "application/json") 
  #data里面存储了所有数据
  esearchresult=data$esearchresult
  count = esearchresult$count
  countData = rbind(countData,data.frame(year=c(year),count=c(count)))
}
print(countData)

library(ggplot2)
ggplot(countData,aes(x=year,y=count))+geom_bar(aes(fill=year), stat="identity")+xlab("year")+ylab("count")


 2018.04.08修正参考代码:

library("httr")

yearData=c()
countData=c()
url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"

for(i in 1:10){
  year=2007+i
  term = paste('(p53[TI]) AND ',year,'[DP]',sep = "")
  r <- POST(url, 
            body = list(
              db='pubmed',
              term=term,
              retmode='json',
              retstart=0,
              retmax=10,
              rettype='uilist'
            )
  )
  
  stop_for_status(r) #清除http状态字符串
  data=content(r, "parsed", "application/json") 
  #data里面存储了所有数据
  esearchresult=data$esearchresult
  count = esearchresult$count
  yearData=c(yearData,year)
  countData=c(countData,count)
}
data=data.frame(year=yearData,count=countData)
print(data)

library(ggplot2)
ggplot(data,aes(x=year,y=count))+geom_bar(aes(fill=year), stat="identity")+xlab("year")+ylab("count")


 
请登录后再评论
| 注册
{{item.nickname}} {{item.create_time}} {{item.floor}}楼
{{item.re_nickname}} 写于 {{item.re_time}}
切换到完整回复
科研狗 2015-2020 京ICP备16006621 科研好助手,专业的科研社交共享平台