Rod*_*igo 5 plot r projection map orthographic
我有一个世界各国的shapefile,从这里下载.我可以用R绘制它
countries <- readOGR("shp","TM_WORLD_BORDERS-0.3",encoding="UTF-8",stringsAsFactors=F)
par(mar=c(0,0,0,0),bg=rgb(0.3,0.4,1))
plot(countries,col=rgb(1,0.8,0.4))
Run Code Online (Sandbox Code Playgroud)
现在我想把它绘制在正交投影(从外太空看到的地球),所以我正在尝试
countries <- spTransform(countries,CRS("+proj=ortho +lat_0=-10 +lon_0=-60"))
Run Code Online (Sandbox Code Playgroud)
我还使用了与X_0和y_0参数(如说这里),但我总是得到错误:
non finite transformation detected:
[1] 45.08332 39.76804 Inf Inf
Erro em .spTransform_Polygon(input[[i]], to_args = to_args, from_args = from_args, :
failure in Polygons 3 Polygon 1 points 1
Além disso: Mensagens de aviso perdidas:
In .spTransform_Polygon(input[[i]], to_args = to_args, from_args = from_args, :
108 projected point(s) not finite
Run Code Online (Sandbox Code Playgroud)
有时在第3个多边形,有时在第7个.那些"Inf"来自哪里?我需要更改任何参数吗?我想像这样绘制地图
但是集中在南美洲之上.谢谢你的帮助!
尝试一下这个maps
包。它会发出有关无法投影的点的警告,但不会给出错误并关闭进程。通过一些小小的摆弄,即设置海洋的填充颜色(这个答案有助于解决这个问题),我能够用几行模拟您附加的地图:
library(maps)
## start plot & extract coordinates from orthographic map
o <- c(-10,-60,0) # oreantation
xy <- map("world",proj="orthographic", orientation=o, bg="black")
xy <- na.omit(data.frame(do.call(cbind, xy[c("x","y")])))
## draw a circle around the points for coloring the ocean
polygon(max(xy$x)*sin(seq(0,2*pi,length.out=100)),max(xy$y)*cos(seq(0,2*pi,length.out=100)),
col="blue4", border=rgb(1,1,1,0.5), lwd=2)
## overlay world map
colRamp <- colorRampPalette(c("lemonchiffon", "orangered"))
map("world",proj="orthographic", orientation=o,
fill=TRUE, col=colRamp(5), add=TRUE)
Run Code Online (Sandbox Code Playgroud)