• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

R语言绘制沈阳地铁线路图

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

##使用leaflet绘制地铁线路图,要求

##(1)图中绘制地铁线路

library(dplyr)
library(leaflet)
library(data.table)
stations<-read.csv("C:\\Users\\BIGDATA\\Desktop\\文件\\BigData\\R语言\\相关作业文档\\3\\第五次实训课数据\\systation.csv");

stations <- arrange(stations,line,line_id)

lines_color <- data.frame("line"=c(1:13,16),"color"=c("#00008B","#000000","#000000","#000000","#823094","#CF047A","#F3560F","#008CC1","#91C5DB","#C7AFD3","#8C2222","#007a61","#ec91cc","#32D2CA"))

pal <- colorFactor(as.character(lines_color$color), domain = stations$line)


Shenyang <- leaflet() %>%
setView(lng=123.44,lat=41.81,zoom = 11) %>% addProviderTiles("CartoDB.Positron")


## 辅助函数绘制线路

draw_line_add <- function(l_no,line_s_id=NULL){
  line_color <- lines_color[lines_color$line==l_no,]$color
  line_data <- stations[stations$line==l_no,]
  if(is.null(line_s_id)){
  draw_lines <- Shenyang %>%
    addPolylines(lat=line_data$gps_lat,lng=line_data$gps_lon,color=line_color)
  }else{
    draw_lines <- Shenyang %>%
      addPolylines(lat=line_data$gps_lat[line_s_id],lng=line_data$gps_lon[line_s_id],color=line_color)
  }
  return(draw_lines)
}

for(l in unique(stations$line)){
  line_length <- nrow(stations[stations$line==l,])
  Shenyang<- draw_line_add(l_no=l)
}

stations_no <- nrow(stations)
for (i in 1:stations_no) {
  s <- stations$station[i]
  stations$lines[i] <- paste(stations[stations$station==s,]$line,sep="",collapse="/")
}

#添加地铁站名
Shenyang<- Shenyang%>%
  addCircleMarkers(stations$gps_lon, stations$gps_lat, popup =paste(stations$station,stations$lines,sep=","),color = pal(stations$line), radius=1.5) %>%
  addLegend(pal=pal,values = stations$line)
Shenyang 



  

##(2)各站点展示进站流量(08:00:00-08:05:00间的数据),流量的大小用标记的大小表示,并且提示线路、站点、流量的具体数值。


library(lubridate)
library(data.table)
library(dplyr)
library(sqldf)
library(leaflet)

stations<-read.csv("C:\\Users\\BIGDATA\\Desktop\\文件\\BigData\\R语言\\相关作业文档\\3\\第五次实训课数据\\systation.csv");
stadata<-read.csv("C:\\Users\\BIGDATA\\Desktop\\文件\\BigData\\R语言\\相关作业文档\\3\\第五次实训课数据\\SY-20150401.csv");
stadata$se<-period_to_seconds(hms(stadata$V3))
stadata<-as.data.table(stadata)
stadata<-filter(stadata,V6==0 & se>=28800 & se<=29100)


getR <- function(quakes) {
  sapply(quakes$count, function(count) {
    count/40
 })
}


stad<-substring(stadata['V4'][,],4)
stad<-data.frame(stad);
names(stad)[1]<-'station'

stations<-stations[order(stations$station),]

count<-sqldf("select station, count(*) from stad group by station")
s<-merge(count,stations,by="station")

names(s)[2]<-c('count')



Shenyang %>% addCircleMarkers(s$gps_lon, s$gps_lat, popup =paste(s$station,s$line,sep=","),color = pal(s$line), radius=getR(s),label=as.character(s$count)) %>% addTiles()

  

 

##使用plotly绘制(17:00:00-17:05:00)出站流量最多的五个站点的出站流量。

library(lubridate)
library(sqldf)
library(plotly)

stations<-read.csv("C:\\Users\\BIGDATA\\Desktop\\文件\\BigData\\R语言\\相关作业文档\\3\\第五次实训课数据\\systation.csv");
stadata<-read.csv("C:\\Users\\BIGDATA\\Desktop\\文件\\BigData\\R语言\\相关作业文档\\3\\第五次实训课数据\\SY-20150401.csv");

stadata$se<-period_to_seconds(hms(stadata$V3))
stadata<-filter(stadata,V6!=0 & se>=61200 & se<=61500)

stad<-substring(stadata['V4'][,],4)
stad<-data.frame(stad);
names(stad)[1]<-'station'


stations<-stations[order(stations$station),]

count<-sqldf("select station, count(*) from stad group by station")
s<-merge(count,stations,by="station")
names(s)[2]<-c('count')
s[17,2]<-s[17,2]*2;
st<-s[-18,];
st<-st[order(-s$count),];
st<-st[1:5,1:2];
plot_ly(st, x=~station,y=~count)

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
R语言学习笔记(二):类与泛型函数发布时间:2022-07-18
下一篇:
学堂在线 R语言随堂笔记(一)发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap