2017-10-21 4 views
1

Mollweide投影を使って世界地図上に線をプロットしようとして失敗しました。私は同じマップ上にポイントをプロットし、うまくいきました。ラインについては、この例を自分のニーズに適合させようとしました:http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/。 私は事前テスト(前のステップ4)で失敗しました。次のコードでは、この行はケニアとオーストラリアを結ぶものとしています。エラーなしで実行されますが、出力には行がありません。 (私もmapprojせずに例をテストし、ラインがあります。)投影されたマップ(mapproj、gcIntermediate)に線を結んでプロットする

library("maps") 
library("mapproj") 
library("geosphere") 

map("world",proj="mollweide", orientation= c(90,0,0), fill=TRUE, col="white", bg="lightblue") 

lon_ke <- 38 
lat_ke <- 1 

lon_aus <- 133 
lat_aus <- -27 

inter <- gcIntermediate(c(mapproject(lon_ke,lat_ke), proj="mollweide", orientation= c(90,0,0)), 
         c(mapproject(lon_aus,lat_aus), proj="mollweide", orientation= c(90,0,0)), 
         n=50, addStartEnd=TRUE) 
lines(inter) 
+0

mapprojとgcIntermediateの唯一の使用法を、ここで見つけた同じコードに追加したいと思います.Rahlf、Thomas。データビジュアライゼーション(R. Springer、2017、doi:10.1007/978-3-319-49751-8、p。 345f。 [here](http://extras.springer.com/2017/978-3-319-49750-1/scriptsanddata.zip) - > maps_world_great_circles.rというスクリプトをダウンロードできます。私はこの例が非常に複雑で、14行目の 'in map(proj = myProj.type、orient = myProj.orient、wrap = T):私は実行できません。 – noschmi

答えて

0

私は(コメントを参照)トーマス・Rahlfの本に基づいて、私の問題への解決策を見つけました。ここに私のスクリプトがあります(著者が記事を公開する場所を視覚化するのに役立ちます)。

library(maps) 
library(geosphere) 
library(mapproj) 

#load data 
locations <- read.csv("articles-authors-locations.csv", header=TRUE, check.names = FALSE) 

#plot map with Mollweide projection 
myProj.type<-"mollweide" 
myProj.orient<-c(90,0,0) 
x<-map(proj=myProj.type,orient=myProj.orient,wrap=T,fill=TRUE, col="white", bg="lightblue",xlim=range(locations$ArticleLong),ylim=range(locations$ArticleLat) 
     ) 

#plot jittered points for authors' locations 
myStartP<-mapproject(jitter(locations$AuthorLong,amount=3),jitter(locations$AuthorLat, amount=1),proj=myProj.type,orient=myProj.orient) 
points(myStartP,col="darkblue",pch=20,cex=1) 

#set transparent colors 
myTColour<-rgb(0,0,0,50,maxColorValue=255) 
red_transp <- adjustcolor("red", alpha.f = 0.4) 

#plot lines and jittered points, connecting authors' and articles locations 
for (i in 1:nrow(locations)) 
{ 
myGC1<-gcIntermediate(c(locations$AuthorLong[i],locations$AuthorLat[i]),c(locations$ArticleLong[i],locations$ArticleLat[i]),addStartEnd=T, n=50) 
moll<-mapproject(myGC1[,1],myGC1[,2],projection=myProj.type,orientation=myProj.orient) 
lines(moll$x,moll$y,lwd=2.5,col=myTColour) 
myDestP<-mapproject(
    jitter(locations$ArticleLong[i], amount=3), 
    jitter(locations$ArticleLat[i], amount=1), 
    proj=myProj.type,orient=myProj.orient) 
points(myDestP,col=red_transp,pch=20,cex=1) 
} 
関連する問題