문제

I am trying to plot a map of the Arctic in Polar stereographic projection. To do this I have imported an already projected shapefile into R using the rGDAL package:

ds <- readOGR(dsn = path, layer = "10m_coastline_ps")

This creates a SpatialLinesDataFrame. Now when I plot this SpatialLinesDataFrame using the plot() function, I am unable to set the plot limits using the xlim and ylim parameters:

plot(ds, xlim=c(-1700000,1700000), ylim=c(-4000000,800000), axes=T)

The plot() function automatically sets the aspect ratio to 1 and forces the axis limits (as explained in this post: igraph axes xlim ylim plot incorrectly). This produces the following plot:

enter image description here

I have tried initializing the plot extent before plotting the SpatialLinesDataFrame as shown below:

mapExtentPr <- rbind(c(-1700000,-4000000), c(1700000,800000))
plot(mapExtentPr, pch=NA)
plot(ds, xlim=c(-1700000,1700000), ylim=c(-4000000,800000), axes=T, asp = 1, add=TRUE)

This sets the right limits but does not maintain the aspect ratio. I have also tried using the clip() function which had no effect.

Is there a way to set the plot limits exactly while maintaining an aspect ratio of 1 (without using ggplot or spplot)?

Note: I have checked this answer already: Is it possible to change the ylim and xlim when the plot has already been drawn?

도움이 되었습니까?

해결책

I ended up using this:

xmin <- -1700000
xmax <- 1700000
ymin <- -4000000
ymax <- 100000

asratio = (ymax-ymin)/(xmax-xmin)

png("greenland_map.png",width=500,height=ceiling(500*asratio))

#plot basemap
plot(ne_10m_coastline_ps,xlim=c(xmin,xmax), ylim=c(ymin,ymax),
     axes=TRUE,asp=1,xaxs="i",yaxs="i")

par(usr=c(xmin,xmax,ymin,ymax))

dev.off()

map with exact axis limits

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top