I have a shapefile of world countries, downloaded from here. I can plot it in R using
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))
Now I wanna plot it in orthographic projection (Earth seen from outer space), so I'm trying
countries <- spTransform(countries,CRS("+proj=ortho +lat_0=-10 +lon_0=-60"))
I also played with the x_0 and y_0 parameters (as stated here), but I always get the error:
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
sometimes in the 3rd polygon, sometimes in the 7th. Where are those "Inf" coming from? I need to change any parameter? I want to plot the map like this
but centered above South America. Thanks for your help!
Give the maps
package a try. It gives a warning about the points that cannot be projected, but it does not give an error and shut the process down. With a little fiddling, namely setting the fill color for the ocean (this answer helped solve that problem), I was able to emulate the map you attached with a couple lines:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With