[R-sig-Geo] Marginless plot output for georegistration of output graphics
Roger Bivand
Roger.Bivand at nhh.no
Thu Jan 18 18:28:19 CET 2007
On Thu, 18 Jan 2007, David Forrest wrote:
> On Thu, 18 Jan 2007, Edzer J Pebesma wrote:
>
> > David Forrest wrote:
> >
> >> On Wed, 17 Jan 2007, Roger Bivand wrote:
> ...
> >> Hmm. I was thinking that the spplot() was the best-practices method for
> >> spatial data.
> >>
> > spplot lets you choose class intervals and colours, but in a different
> > way than base graphics do. I don't think there is a best-practices for
> > spatial data, in the end best practice to me is that a plotting engine
> > does not leave its traces in the plot. However, R has two plotting
> > routes, base and lattice/grid, and sp provides (hopefully) convenient
> > wrapper functions to use either. Lattice then has the added (major)
> > advantage of auto-legends/classes (to some extent) and conditioning.
>
> I see.
>
> In the documentation, the lattice-based 'spplot' seemed more prominent,
> and I found it unclear that the plot() was a good option.
>
> On plot(SpatialPointsDataFrame) is it possible to eliminate the margins
> there as well? I can do it with lattice using the theme.novplotting from
> before:
>
> library(maptools);library(stats)
> qk<-SpatialPointsDataFrame(quakes[,c(2:1)],quakes)
> proj4string(qk)<-CRS("+proj=longlat")
> qk.lp<-spplot(qk,'mag',key.space=list(x=0.25,y=.2,corner=c(1,1)),
> par.settings=theme.novpadding,
> scales=list(axs='i',draw=FALSE),
> xlim=bbox(qk)[1,],ylim=bbox(qk)[2,])
> print(qk.lp)
>
> # With a controlled-size png file:
> myheight=600;mywidth=myheight/mapasp(qk) #
> png(file='mymap.png',width=mywidth,height=myheight,bg='transparent')
> print(qk.lp)
> dev.off()
> system(paste('display','mymap.png'))
>
> ######### back in base:
> # Non-spatial as plot(x,y) -- No margin
> myheight=600;mywidth=myheight/mapasp(qk) #
> png(file='mymap.png',width=mywidth,height=myheight,bg='transparent')
> par(mar=c(0,0,0,0))
> plot(qk$long,qk$lat,xaxs='i',yaxs='i',xlab=FALSE,axes=FALSE,
> xlim=bbox(qk)[1,],ylim=bbox(qk)[2,] # unnecessary
> )
> dev.off()
> system(paste('display','mymap.png'))
>
> ##########
> # as SpatialPoints -- maybe the standard 4% margins?
> myheight=600;mywidth=myheight/mapasp(qk) #
> png(file='mymap.png',width=mywidth,height=myheight,bg='transparent')
> par(mar=c(0,0,0,0))
> plot(qk,xaxs='i',yaxs='i',xlab=FALSE,axes=FALSE,
> xlim=bbox(qk)[1,],ylim=bbox(qk)[2,])
> dev.off()
> system(paste('display','mymap.png'))
> #######################
>
> The last two examples show a difference between the margin handling in
> plotting spatial points data and regular x,y data.
I think that plot.window() inside plot.Spatial is not respecting the
xaxs="i", yaxs="i" settings, probably they are not being passed through
correctly. By forcing them inside plot.Spatial:
par(usr=c(t(bbox)))
we do get there, but that is certainly brutal. Setting them in par() also
doesn't carry through plot.window().
Roger
>
> > I agree that not having a way to suppress the key in spplot for
> > SpatialPointsDataFrame is an omission. I'll try to get the auto.key =
> > FALSE working. There's quite some code in sp for this particular method,
> > as xyplot (which it wraps) doesn't automatically classify points given
> > an attribute value; the extra work is done in sp here, unlike the other
> > spplot methods that wrap levelplot.
>
> Cool. Moving the key to inside the bbox is a bit awkward.
>
> Thanks for your time,
> Dave
>
--
Roger Bivand
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-sig-Geo
mailing list