服务热线
178 0020 3020
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')
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')

附件