[R-sig-Geo] Marginless plot output for georegistration of output graphics

David Forrest drf5n at maplepark.com
Thu Jan 18 17:37:29 CET 2007


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 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
-- 
  Dr. David Forrest
  drf at vims.edu                                    (804)684-7900w
  drf5n at maplepark.com                             (804)642-0662h
                                    http://maplepark.com/~drf5n/




More information about the R-sig-Geo mailing list