Might as well let the cat out of the bag and say that I have been trying for about a day to figure out what is happening when I call plot
for an object of class SpatialPolygons*
. My instinct is to look for plot.SpatialPolygonsDataFrame
, the approach which works for any number of other examples I've seen & encountered, but this failed.
Quick example:
US States .shp file here.
library(maptools)
us.states<-readShapePoly("cb_2014_us_state_5m.shp")
plot(us.states)
A bit dumpy but whatever--the point is that a simple call to plot
and somewhere deep down R
knew which method to call in order to give us a representation of all the shapes.
After searching around a bit, I tried two of the other approaches suggested by various SO Q&As, first and foremost:
> methods(plot)
[1] plot.aareg* plot.acf*
[3] plot,ANY,ANY-method plot.cox.zph*
[5] plot.data.frame* plot.decomposed.ts*
[7] plot.default plot.dendrogram*
[9] plot.density* plot.ecdf
[11] plot.factor* plot.formula*
[13] plot.function plot.hclust*
[15] plot.histogram* plot.HoltWinters*
[17] plot.isoreg* plot.lm*
[19] plot.medpolish* plot.mlm*
[21] plot.ppr* plot.prcomp*
[23] plot.princomp* plot.profile.nls*
[25] plot.raster* plot.shingle*
[27] plot,SpatialGrid,missing-method plot,SpatialLines,missing-method
[29] plot,Spatial,missing-method plot,SpatialPixels,missing-method
[31] plot,SpatialPoints,missing-method plot,SpatialPolygons,missing-method
[33] plot.spec* plot.spline*
[35] plot.stepfun plot.stl*
[37] plot.survfit* plot.table*
[39] plot.times* plot.trellis*
[41] plot.ts plot.tskernel*
[43] plot.TukeyHSD* plot.xyVector*
[45] plot.zoo*
The answer would appear to be in slots 27-32; however, each is followed by a vexing comma! No mention that this is possible in ?methods
and ?plot,SpatialPolygons,missing-method
is an error. A quick search for missing-method
turns up nothing of use and there's again no mention in ?methods
.
OK; moving on. What about getS3method
? getMethod
? getMethods
? getAllMethods
??
> getS3method("plot","SpatialPolygonsDataFrame")
Error in getS3method("plot", "SpatialPolygonsDataFrame") :
S3 method 'plot.SpatialPolygonsDataFrame' not found
> getMethod("plot","SpatialPolygonsDataFrame")
Error in getMethod("plot", "SpatialPolygonsDataFrame") :
no method found for function 'plot' and signature SpatialPolygonsDataFrame
The latter two are deprecated & also return nothing.
So apparently these functions are just a stand-in for my first instincts.
So now what? How can I tell which method is being called by plot
when it is passed a SpatialPolygonsDataFrame
? Is there any general approach to this problem that supersedes the approach I used above?
Edit:
Sort of by accident I stumbled upon this (=?`Spatial-Polygons-class`
) which says:
The
plot
method for spatial polygons takes the following arguments:
but it still doesn't say what that method is, exactly.