【问题标题】:Plot connecting lines on a projected map (mapproj, gcIntermediate)在投影地图上绘制连接线(mapproj、gcIntermediate)
【发布时间】:2017-10-21 20:20:39
【问题描述】:

我尝试使用 Mollweide 投影在世界地图上绘制线条没有成功。我还在同一张地图上绘制了点,结果很好。对于线条,我尝试根据我的需要调整这个示例:http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/。 我已经通过预测试(前文中的第 4 步)失败了。在下面的代码中,这条线应该连接肯尼亚和澳大利亚。它运行没有错误,但输出中没有行。 (我也测试了没有 mapproj 的例子,这条线就在那里。)

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)

【问题讨论】:

  • 我想补充一点,mapproj 和 gcIntermediate 的唯一用法是在我在这里找到的相同代码中:Rahlf,Thomas。使用 R. Springer 进行数据可视化,2017,doi:10.1007/978-3-319-49751-8,p。 345f。您可以下载脚本here --> maps_world_great_circles.r。我发现这个例子过于复杂,它不适合我,在第 14 行 In map(proj = myProj.type, orient = myProj.orient, wrap = T) : projection failed for some data

标签: r map-projections geosphere


【解决方案1】:

我根据 Thomas 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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多