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:
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?
Best Answer
I ended up using this: