[R] Plot SpatialLinesDataFrame with xlim & ylim
Edzer J. Pebesma
e.pebesma at geo.uu.nl
Wed Jul 11 08:56:14 CEST 2007
The plot method for SpatialLinesDataFrame objects resides in package sp,
and questions regarding it are easier noticed on the r-sig-geo mailing
The reason why they are plotted with aspect ratio 1 is that they are
assumed to be spatial (geographical) data, and assume that 1 m north
equals 1 m west -- think of a map. The exception is when the projection
argument is set to longlat data (i.e. decimal degrees North/East), where
the aspect ratio is computed differently, such that the argument above
more or less holds.
You should be able to override the default aspect setting by explicitly
passing the e.g. asp=0.5 argument to plot.
Here's the comment in the documentation of plot for Spatial objects
(such as SpatialLinesDataFrame):
The default aspect for map plots is 1; if however data are not projected
(coordinates are longlat), the aspect is by default set to 1/cos(My *
pi)/180) with My the y coordinate of the middle of the map (the mean of
ylim, which defaults to the y range of bounding box).
The argument |setParUsrBB| may be used to pass the logical value |TRUE|
to functions within |plot.Spatial|. When set to |TRUE|, par(“usr”) will
be overwritten with |c(xlim, ylim)|, which defaults to the bounding box
of the spatial object. This is only needed in the particular context of
graphic output to a specified device with given width and height, to be
matched to the spatial object, when using par(“xaxs”) and par(“yaxs”) in
addition to |par(mar=c(0,0,0,0))|.
I'm running windows xp, R 2.3.1 with maptools 0.6-6, I guess.
When plotting from a large SpatialLinesDataFrame and using xlim & ylim to reduce the area, the plot axes automatically have the same scale size, even if xlim and ylim ranges differ.
tmp <- readShapeLines(filepath)
The y-axis range is actually 47-54, same range as the x-axis. What am I doing wrong? Should I be using a different object for simple coastline & river data?
Thanks in advance!
More information about the R-help