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/m.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燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP