中国经管类核心期刊地域分布数据可视化

最近在看文献,看的有些烦躁了,想找点儿数据练练手,刚好看到百度百科有这个关于经管类核心期刊的汇总表,顺手就抓过来练习练习。

本来百度百度中核心期刊栏目的列表里,关于经济学72中核心期刊的详细地址不全,我申请了编辑字条,编完一直在审核,想想算了,根据百度百科的审核流程和效率,估计不知道要申到猴年马月了,自己搜了确实的地址信息。

以下数数据的爬取、清洗和可视化过程:


数据抓取:

加载包:

1
2
3
4
5
6
7
8
9
10
library(rvest)
library(stringr)
library(dplyr)
library(ggplot2)
library(plyr)
library(rjson)
library(Cairo)
library(Cairo)
library(showtext)
library(maptools)

表格爬取(这里用revst来爬,效率特别高)

1
2
url<-"http://baike.baidu.com/link?url=VRCRtZ-GR4Lv483tBm2d6IQ3mOjTlcc1z80EBBzFwCGAlDT16NvxH_yqshJdSD95_AEEu_Hzg4uE3ok3bDIohkkl9sTwpE9cVJcRP7RpAmVBIeEmwZ4gdXNetbA8lvmU"
info<-read_html(url,encoding="UTF-8")%>%html_nodes("table")%>%html_table(header=TRUE,fill=TRUE)

数据清洗:

表格的提取过程:

1
2
economic<-info[[1]][,-1];names(economic)<-c("Name","Address");economic$Class<-"C"
mangement<-info[[2]][,-1];names(mangement)<-c("Name","Address");mangement$Class<-"M"

打开数据编辑器,自己把缺失的地址补全

1
fix(economic)

剔除掉地址中的哪些邮箱类信息(可能会干扰经纬度抓取的准确性)

1
2
3
4
myfulldata<-rbind(economic,mangement)
myfulldata$Address<-sub("\\(\\d.+\\)","",myfulldata$Address)
myfulldata$Address<-sub("\\(\\d.+\\)","",myfulldata$Address)
myfulldata$Address<-sub("\\d.+\\信箱","",myfulldata$Address)


抓取经纬度数据

使用过百度地图的API匹配经纬度(各位小伙伴儿高抬贵手,自己去申请个API把,不要老拿我的API玩耍,这个有限额,用完了就不能用了)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
baidu_lng <- c()
baidu_lat <- c()
ak<-"X8zlxPUdSe2weshrZ1WqnWxb43cfBI2N"
address<-myfulldata$Address
for(location in address){
url<-paste("http://api.map.baidu.com/geocoder/v2/?ak=",ak,"&callback=renderOption&output=json&address=",location,sep="")
url_string <- URLencode(url)
json<- readLines(url_string, warn=F)
geo <- fromJSON(substr(json,regexpr("\\(",json)+1,nchar(json)-1))
lng<-geo$result$location$lng
lat<-geo$result$location$lat
baidu_lng<-c(baidu_lng,lng)
baidu_lat<-c(baidu_lat,lat)
}
result<-data.frame(address=address,longitude=baidu_lng,latitude=baidu_lat,stringsAsFactors=FALSE)

合并经纬度数据:

1
2
3
mynewfulldata<-merge(myfulldata,result,by.x="Address",by.y="address",all.x=T)
mynewfulldata<-unique(mynewfulldata)
mynewfulldata<-mynewfulldata[,c(2,1,4,5,3)];names(mynewfulldata)[3:4]<-c("lon","lat")


地域可视化:

导入地图数据:

1
2
china_map <- readShapePoly("D:/R/rstudy/CHN_adm/bou2_4p.shp")
china_map1 <- fortify(china_map)

接下来我们通过几张图表来展示社科经管类核心期刊的地域分布、城市分布情况。

经管类总体数量分布:

提取出所有的地址中地级市数量:

1
2
3
4
5
6
7
8
9
10
11
12
13
diyufenbujing<-myfulldata$Address
diyufenbu<-sub("中国","",diyufenbujing)
part1<-grep("市",diyufenbu,value=T)
part1<-sub("(安徽|四川省|湖南省)","",part1)
order<-gregexpr("市",part1)
city<-c()
for(j in 1:length(part1)){
city<-substring(part1,0,order[[j]][1])
}
part2<-grep("市",diyufenbu,value=T,invert =T)
part2<-sub("四川","",part2)
cityvalue2<-paste0(substring(part2,1,2),"市")
cityvalue<-c(city,cityvalue2)%>%count()%>%arrange(-freq)

所有核心期刊的城市分布情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CairoPNG(file="hexinqikanall.png",width=800,height=600)
font.add("myfont","msyh.ttc")
showtext.begin()
ggplot(cityvalue,aes(reorder(x,freq),freq))+
geom_bar(fill="#0C8DC4",stat="identity")+
coord_flip()+
labs(title="经管类核心期刊数量城市分布",caption="数据来源:百度百科")+
geom_text(aes(label=freq),hjust=1.2,colour="white",size=8)+
theme_bw()+
theme(
panel.border=element_blank(),
panel.grid.major=element_line(linetype="dashed"),
panel.grid.minor=element_blank(),
plot.title=element_text(size=15,colour="#003087",family="myfont"),
plot.caption=element_text(hjust=0,size=10),
axis.title=element_blank(),
axis.text=element_text(size=15)
)
showtext.end()
dev.off()

hexinqikanall

经济学核心期刊城市分布:

1
2
3
4
5
6
7
8
9
10
11
12
diyufenbujingji<-myfulldata[which(myfulldata$Class=="C"),]$Address
diyufenbujingji<-sub("中国","",diyufenbujingji)
part1<-grep("市",diyufenbujingji,value=T)
part1<-sub("(河南省|湖南省)","",part1)
order<-gregexpr("市",part1)
city<-c()
for(j in 1:length(part1)){
city<-substring(part1,0,order[[j]][1])
}
part2<-grep("市",diyufenbujingji,value=T,invert =T)
cityvalue2<-paste0(substring(part2,1,2),"市")
cityvalue<-c(city,cityvalue2)%>%count()%>%arrange(-freq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
setwd("F:/微信公众号/公众号——数据小魔方/2017年3月/20170319")
CairoPNG(file="jingjixue1.png",width=900,height=620)
font.add("myfont","msyh.ttc")
showtext.begin()
ggplot(cityvalue,aes(reorder(x,freq),freq))+
geom_bar(fill="#0C8DC4",stat="identity")+
coord_flip()+
labs(title="经济学核心期刊城市分布",caption="数据来源:百度百科")+
geom_text(aes(label=freq),hjust=1,colour="white",size=7)+
theme_bw()+
theme(
panel.border=element_blank(),
panel.grid.major=element_line(linetype="dashed"),
panel.grid.minor=element_blank(),
plot.title=element_text(size=15,colour="#003087",family="myfont"),
plot.caption=element_text(hjust=0,size=10),
axis.title=element_blank(),
axis.text=element_text(size=15)
)
showtext.end()
dev.off()

jingjixue1

管理学核心期刊城市分布:

1
2
3
4
5
6
7
8
9
10
11
12
diyufenbujinggl<-myfulldata[which(myfulldata$Class=="M"),]$Address
diyufenbujinggl<-sub("中国","",diyufenbujinggl)
part1<-grep("市",diyufenbujinggl,value=T)
part1<-sub("(安徽省|四川省)","",part1)
order<-gregexpr("市",part1)
city<-c()
for(j in 1:length(part1)){
city<-substring(part1,0,order[[j]][1])
}
part2<-grep("市",diyufenbujinggl,value=T,invert =T)
cityvalue2<-paste0(substring(part2,1,2),"市")
cityvalue2<-c(city,cityvalue2)%>%count()%>%arrange(-freq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CairoPNG(file="jingjixue2.png",width=800,height=600)
font.add("myfont","msyh.ttc")
showtext.begin()
ggplot(cityvalue2,aes(reorder(x,freq),freq))+
geom_bar(fill="#0C8DC4",stat="identity")+
coord_flip()+
labs(title="管理学核心期刊数量城市分布",caption="数据来源:百度百科")+
geom_text(aes(label=freq),hjust=2,colour="white",size=10)+
theme_bw()+
theme(
panel.border=element_blank(),
panel.grid.major=element_line(linetype="dashed"),
panel.grid.minor=element_blank(),
plot.title=element_text(size=15,colour="#003087",family="myfont"),
plot.caption=element_text(hjust=0,size=10),
axis.title=element_blank(),
axis.text=element_text(size=15)
)
showtext.end()
dev.off()

jingjixue2

下面我们通过几张数据地图来观察一下这些期刊在地图空间分布上的趋势。

经济学类核心期刊地域分布

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mynewfulldata1<-filter(mynewfulldata,Class=="C")
CairoPNG(file="hexinqikanC.png",width=1200,height=640)
font.add("myfont","msyh.ttc")
showtext.begin()
ggplot()+
geom_polygon(data=china_map1,aes(x=long,y=lat,group=group),col="grey60",fill="white",size=.2,alpha=.4)+
geom_polygon(data=mynewfulldata,aes(x=lon,y=lat,fill = ..level..),stat="density_2d",alpha=.8,color=NA)+
geom_point(data=mynewfulldata,aes(x=lon,y=lat),shape=21,size=3,fill="orange",col="white")+
scale_fill_gradient2(low="white",mid="yellow", high = "red")+
coord_map("polyconic")+
guides(fill=FALSE)+
labs(title="经济学核心期刊地域分布密度图",caption="数据来源:百度百科")+
theme(
title=element_text(family="myfont",size=18),
plot.title=element_text(size=24),
panel.grid=element_blank(),
panel.background=element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
plot.caption=element_text(hjust=0)
)
showtext.end()
dev.off()

hexinqikanC

管理学核心期刊地域分布

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
mynewfulldata2<-filter(mynewfulldata,Class=="M")
CairoPNG(file="hexinqikanM.png",width=1200,height=640)
font.add("myfont","msyh.ttc")
showtext.begin()
ggplot()+
geom_polygon(data=china_map1,aes(x=long,y=lat,group=group),col="grey60",fill="white",size=.2,alpha=.4)+
geom_polygon(data=mynewfulldata2,aes(x=lon,y=lat,fill = ..level..),stat="density_2d",alpha=.8,color=NA)+
geom_point(data=mynewfulldata2,aes(x=lon,y=lat),shape=21,size=3,fill="#0C8DC4",col="white")+
scale_fill_gradient2(low="white",mid="yellow", high = "red")+
coord_map("polyconic")+
guides(fill=FALSE)+
labs(title="管理学核心期刊地域分布密度图",caption="数据来源:百度百科")+
theme(
title=element_text(family="myfont",size=18),
plot.title=element_text(size=24),
panel.grid=element_blank(),
panel.background=element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
plot.caption=element_text(hjust=0)
)
showtext.end()
dev.off()

hexinqikanM

经济学和管理学核心期刊地域分布对比图。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CairoPNG(file="jingguanphoto.png",width=1200,height=640)
font.add("myfont", "msyh.ttc")
showtext.begin()
ggplot()+
geom_polygon(data=china_map1,aes(x=long,y=lat,group=group),col="grey60",fill="white",size=.2,alpha=.4)+
geom_point(data=mynewfulldata,aes(x=lon,y=lat),shape=21,size=8,fill="transparent",col="#014D64")+
geom_point(data=mynewfulldata2,aes(x=lon,y=lat),shape=21,size=3,fill="#C72E29",col="transparent",alpha=.6)+
coord_map("polyconic") +
labs(title="中国社科类经管核心期刊地域分布图",caption="数据来源:百度百科")+
annotate("text", x=63.4, y=45, label="○ C: 经济学", color= "#014D64", size=6.5) +
annotate("text", x=65, y=42, label=" ● M: 管理学", color= "#C72E29", size=6) +
theme(
title=element_text(family="myfont",size=18),
plot.title=element_text(size=24),
plot.caption=element_text(family="myfont",size=18,hjust=0),
panel.grid = element_blank(),
panel.background = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
legend.position = c(0.02,0.6),
)
showtext.end()
dev.off()

jingguanphoto

不知道大家看了以上核心期刊的地域分布滞后,内心作何感想呢,本来想写几句短评到的,但是相信通过以上可视化形式的呈现,大家都已经明白我想说什么了!

再者自己是个学渣,这个话题不适合我~—~,有啥感想,都可以写在底部评论里,让我看到你们的声音!


联系方式:
wechat:ljty1991
Mail:578708965@qq.com
个人公众号:数据小魔方(datamofang)

qq交流群:[魔方学院]298236508

个人简介:
杜雨
财经专业研究僧;
伪数据可视化达人;
文科背景的编程小白;
喜欢研究商务图表与地理信息数据可视化,爱倒腾PowerBI、SAP DashBoard、Tableau、R ggplot2、Think-cell chart等诸如此类的数据可视化软件,创建并运营微信公众号“数据小魔方”。
Mail:578708965@qq.com


备注信息:
知识共享许可协议
本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。

坚持原创技术分享,您的支持将鼓励我继续创作!