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. E.g.: tmp <- readShapeLines(filepath) plot(tmp,xlim=c(-126,-119),ylim=c(50,51)) 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! Michael _______________________________________________________ Michael Folkes Salmon Stock Assessment Canadian Dept. of Fisheries & Oceans Pacific Biological Station 3190 Hammond Bay Rd. Nanaimo, B.C., Canada V9T-6N7 Ph (250) 756-7264 Fax (250) 756-7053 folkesm@pac.dfo-mpo.gc.ca [[alternative HTML version deleted]]
Michael, The plot method for SpatialLinesDataFrame objects resides in package sp, and questions regarding it are easier noticed on the r-sig-geo mailing list. 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))|. -- Edzer 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. E.g.: tmp <- readShapeLines(filepath) plot(tmp,xlim=c(-126,-119),ylim=c(50,51)) 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! Michael
Folkes, Michael
2007-Aug-31 00:36 UTC
[R] Lattice:can't subset in panel function using other variables
I've succeeded doing a subset within the panel function of xyplot - if I'm subsetting based on either the value of 'x' or 'y' (e.g. below). However, I wish to subset based on the value of another variable and colour that one plotted point. It's not working. Either it doesn't plot the coloured data point, or if I sort the data differently it colours one datapoint, but the wrong one. I assume this means it's not getting the right subscripts? Finally I can sort of see the light as if I remove the conditioning variable (week) and subset before the xyplot (e.g. week==1) to get just one panel, it plots the correct data including the correct single red point. Where am I erring? _______________________________________ print(xyplot(yval~xval|week,data=mydata, panel=function(x,y,subscripts){ #panel.xyplot(x,y,type='p',col=1,cex=.5) panel.xyplot(x[y<=40],y[y<=40],type='p',col=2,cex=.5) # <-----this works panel.xyplot(x[mydata$yr==2005],y[mydata$yr==2005],type='p',pch=16,col=2,cex=.5) # <-----sometimes this won't work or it colours wrong datapoint })) ___________________________ Thanks very much! Michael Folkes _______________________________________________________ Michael Folkes Salmon Stock Assessment Canadian Dept. of Fisheries & Oceans Pacific Biological Station 3190 Hammond Bay Rd. Nanaimo, B.C., Canada V9T-6N7 Ph (250) 756-7264 Fax (250) 756-7053 folkesm@pac.dfo-mpo.gc.ca [[alternative HTML version deleted]]