# 多维放射状流向图的最佳布局方案

#加载包： library(ggplot2) library(dplyr) library(rgdal) library(shiny) library(shinythemes)

##转换为数据框并合并城市数据： china_map <- fortify(china_map) province_city <- read.csv("D:/R/rstudy/Province/chinaprovincecity.csv",stringsAsFactors = FALSE,check.names = FALSE)

###构造线条起始点数据： city<-c("北京","上海","重庆","天津","武汉","南京","广州","沈阳","西安","郑州") city_data<-merge(city,city)%>%rename(Start=x,End=y)%>%arrange(Start) city_data<-city_data%>%merge(province_city[,c("city","jd","wd")],by.x="Start",by.y="city",all.x=TRUE)%>%rename(Start_long=jd,Start_lat=wd) city_data<-city_data%>%merge(province_city[,c("city","jd","wd")],by.x="End",by.y="city",all.x=TRUE)%>%rename(End_long=jd,End_lat=wd) city_data<-transform(city_data,zhibiao1=runif(nrow(city_data),0,100),zhibiao2=runif(nrow(city_data),0,100),zhibiao3=runif(nrow(city_data),0,100))

###理所当然的普通做法1： ggplot()+ geom_polygon(data=china_data,aes(x=long,y=lat,group=group),fill="white",colour="grey60")+ geom_segment(data=city_data,aes(x=Start_long,y=Start_lat,xend=End_long,yend=End_lat,size=zhibiao1),colour="black")+ coord_map("polyconic") + scale_size_area(max_size=2)+ theme_void()

###最合适的做法1：图形分面： ggplot()+

geom_polygon(data=china_data,aes(x=long,y=lat,group=group),fill="white",colour="grey60")+ geom_segment(data=city_data,aes(x=Start_long,y=Start_lat,xend=End_long,yend=End_lat),colour="black")+ geom_point(data =city_data,aes(x=End_long,y=End_lat,size=zhibiao1),shape=21,fill="#8E0F2E",colour="black",alpha=0.4)+ scale_size_area(max_size=6)+ coord_map("polyconic") + facet_wrap(~Start,nrow = 2)+ theme_void()

###最合适的做法2：

Shiny动态交互图：

city_list<-list("北京"="北京","上海"="上海","重庆"="重庆","天津"="天津","武汉"="武汉","南京"="南京","广州"="广州","沈阳"="沈阳","西安"="西安","郑州"="郑州") ui <-shinyUI(fluidPage( theme=shinytheme("cerulean"), titlePanel("Population Structure Data"), sidebarLayout( sidebarPanel( radioButtons("var1","City",city_list,inline=FALSE), selectInput("var2","Value",c("zhibiao1"="zhibiao1","zhibiao2"="zhibiao2","zhibiao3"="zhibiao3"),selected="zhibiao1") ), mainPanel(h2("Trade Stream"),plotOutput("distPlot")) ) ))

server<-shinyServer(function(input,output){ output\$distPlot <- renderPlot({ mydata=filter(city_data%>%filter(Start==input\$var1)) argu<-switch(input\$var2,zhibiao1=mydata\$zhibiao1,zhibiao2=mydata\$zhibiao2,zhibiao3=mydata\$zhibiao3) ggplot(mydata)+ geom_polygon(data=china_data,aes(x=long,y=lat,group=group),fill="white",colour="grey60")+ geom_segment(aes(x=Start_long,y=Start_lat,xend=End_long,yend=End_lat),colour="black")+ geom_point(aes(x=End_long,y=End_lat,size=argu),shape=21,fill="#8E0F2E",colour="black",alpha=0.4)+ scale_size_area(max_size=6)+ coord_map("polyconic") + theme_void() }) }) shinyApp(ui=ui,server=server)

459 篇文章81 人订阅

0 条评论

## 相关文章

54560

35230

### 基于电子海图的水面无人艇全局路径规划

该论文已经在ICMIR2017会议上发表，附上springer的文献地址 Research and Implementation of Global Pat...

33850

### 关于深度学习框架Hamaa与Python API文档生成工具Sophon

14130

【新智元导读】一项新的研究旨在使用生成对抗网络（GAN） 来加快密码破解的速度。斯蒂文斯理工学院的研究人员用类似“AlphaGo”的方法，利用超过 4300 万...

36960

### 基于电子海图的水面无人艇全局路径规划

Research and Implementation of Global Path Planning for Unmanned Surface Vehicle...

43250

39220

40450

43750

1.2K00