[R] [R-sig-Geo] Plot SpatialLinesDataFrame with xlim & ylim
Roger.Bivand at nhh.no
Wed Jul 11 10:30:00 CEST 2007
On Wed, 11 Jul 2007, Edzer J. Pebesma wrote:
> 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))|.
Yes, if you look at how the GE_SpatialGrid() function in maptools works -
you'll see how it meddles with the actual regional extents and the device
size. I think Michael's data should also have been set to longlat:
proj4string(tmp) <- CRS("+proj=longlat")
The key is realising that the axes are driven by the device shape, not by
the xlim/ylim as such, as Edzer says.
> 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!
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-help