R2-03 第二阶段第四次作业

微思微丝 2018-04-15 15:57:05 阅读: 1539

    R语言之统计某个研究领域的研究趋势

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('(gold nanorods[MESH]) 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=factor(year),y=count))+
 geom_bar(aes(fill=count),stat='identity',width = 0.8)+
 geom_text(label=data$count,colur='red',vjust=-0.5)+##给每个柱子添加文字标签
 theme(axis.ticks = element_blank(),##隐藏刻度但是显示标签
       panel.grid.minor.y=element_blank(),
    panel.grid.major.y = element_blank(),
    axis.text.y =element_blank())+##隐藏横向的参考线和纵轴数值标签
 labs(x='year',y='count')

20180415-2.png

library(ggplot2)
 ggplot(data,aes(x=reorder(year,count),y=count))+
 geom_bar(aes(fill=year),stat='identity',width = 0.8)+
 geom_text(label=data$count,colur='red',vjust=-0.5)+##给每个柱子添加文字标签
 theme(axis.ticks = element_blank(),##隐藏刻度但是显示标签
       panel.grid.minor.y=element_blank(),
       panel.grid.major.y = element_blank(),
       axis.text.y =element_blank())+##隐藏横向的参考线和纵轴数值标签
 labs(x='year',y='count')

20180415-1.png

 

 

 
邀请讨论

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
{{item.nick_name}} 受邀请回答 {{item.create_time}}
{{item.refer_comment.nick_name}} {{item.refer_comment.create_time}}

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
切换到完整回复 发送回复
赞({{item.count_zan}}) 踩({{item.count_cai}}) 删除 回复 关闭
科研狗©2015-2024 科研好助手,京ICP备20005780号-1 建议意见

服务热线

178 0020 3020

微信服务号