R_Language 板


LINE

[问题类型]: 程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来) [软体熟悉度]: 请把以下不需要的部份删除 入门(写过其他程式,只是对语法不熟悉) [问题叙述]: 各位大大好,我目前急迫性需要在一个国家地图上画出几个城市的地理位置点 以及画出连接两个地理位置的连接线,但线的部份一直无法成功画出来 ,想在此请求帮忙 我使用Shapefile里的数据,已经将地图和城市的代码和地理位置画出来。 我程式里有两个csv档案,A档包含该国家的城市代码以及地理 位置(longitude, latitude)清单,B档包含哪两个连接点需要被连接起来 的清单。 因为Shapefile里面的地理位置数据单位为UTM(Universal Transverse Mercator) coordinate system,我已在我的codes中将csv A档的longtitude/latitude转换为 UTM 单位,城市点也画出来了,run codes的时候也没有bugs, 所以我怀疑的是 我下面的codes最後一部份gcintermediate() 那边可能有地理位置单位的问题以至 系统无法找出UTMcoordinates画连接线,但我已试非常多不同方法,依然无法 画出连接线,麻烦大大们的帮忙,会非常感激! 这是目前的OUTPUT结果: https://www.dropbox.com/s/tvd1chw3e6tyy6y/paint.png?dl=0 [程式]: # Load necessary packages library(maps) library(sp) library(maptools) library(geosphere) library(rgdal) #library(ggmap) # Function that returns coordinates of a given location getCoords<-function(location,df){ return(df[match(x=location,df[,"ResidentID2012"]),][,c(4,3)]) } # Read in the Shapefile Map <-readShapeSpatial("County.shp") # Read CSV file containing coordinates and edges familylocation2012<-read.csv(file="CityLocation.csv",sep=",",header=TRUE) networkconnection<-read.csv(file="NodesConnection.csv",sep=",",header=TRUE) # Plot the graph itself plot(Map,lwd=0.01,bg="#242424",col="#0000CD") # Setting existing coordinate as lat-long system cord.dec <- SpatialPoints(cbind(familylocation2012$Longitude, familylocation2012$Latitude), proj4string = CRS("+proj=longlat")) # Transforming coordinate to UTM using EPSG=19938 for WGS=84, UTM Zone=35N cord.UTM <- spTransform(cord.dec, CRS("+init=epsg:3301")) # Plot the nodes on the graph points(cord.UTM, pch=16,cex=1.5, col = "white") # Label the nodes text(attr(cord.UTM, "coords")[,1], attr(cord.UTM, "coords")[,2], familylocation2012$ResidentID2012,cex=1,adj=0,pos=1,col="#C2C2C2") #Connet points and plot the line for (j in 1:nrow(networkconnection)){ plotLine(networkconnection[j,]$BEGINPOINT,networkconnection[j,]$ENDPOINT,familylocation2012) } # Plot a great circle from 'Begin' to 'Endpoint' names. plotLine<-function(BEGINPOINT,ENDPOINT,df){ inter<-gcIntermediate(p1=getCoords(BEGINPOINT,df), p2=getCoords(ENDPOINT,df), n=50,addStartEnd=TRUE) lines(inter, col="white",cex=2,lwd=2) } [环境叙述]: > sessionInfo() R version 3.2.1 (2015-06-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 8 x64 (build 9200) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rgdal_1.0-4 geosphere_1.4-3 maptools_0.8-36 maps_2.3-11 sp_1.1-1 loaded via a namespace (and not attached): [1] tools_3.2.1 foreign_0.8-63 grid_3.2.1 lattice_0.20-31 > > sessionInfo() R version 3.2.1 (2015-06-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 8 x64 (build 9200) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rgdal_1.0-4 geosphere_1.4-3 maptools_0.8-36 maps_2.3-11 sp_1.1-1 loaded via a namespace (and not attached): [1] tools_3.2.1 foreign_0.8-63 grid_3.2.1 lattice_0.20-31 > [关键字] Graphics, social network, R mapping --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 67.183.158.162
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1439734592.A.10B.html
1F:→ celestialgod: dropbox连结有误,你要用分享的网址才有用 08/16 22:20
※ 编辑: Learn2015 (67.183.158.162), 08/16/2015 22:30:38
2F:→ Learn2015: 感谢celestialgod!dropbox连结已更正 08/16 23:47







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP