[R-sig-Geo] Overlay bubble chart on map

Roger Bivand Roger.Bivand at nhh.no
Mon Aug 17 09:22:58 CEST 2009


On Sun, 16 Aug 2009, Rebecca Ross wrote:

>
> Dear All,
>
> I am new to this list, so apologies if this question has been asked and
> answered many times before!
>
> I would like to overlay a bubble chart onto a map so that the bubbles
> correspond to particular points on the map. I have the shape file for the map
> and the lat long co-ordinates for the points. Could anyone tell me how to put
> the two together? The suggestions I found so far are plot.Map and plot.Spatial,
> neither of which work.
>
> I am working to a bit of a deadline, so a response today would be really
> helpful.

If your shapefile data are lines, read them as a SpatialLinesDataFrame 
object (readOGR() in rgdal) - if polygons as a SpatialPolygonsDataFrame 
object (same function) and coerce to SpatialLines, then use the sp.layout= 
argument in the bubble() function in sp - this argument is documented on 
the help page to spplot() methods in sp:

dsn <- system.file("vectors", package = "rgdal")[1]
scot_BNG <- readOGR(dsn, "scot_BNG")
# using the data in the shapefile as an example
pts <- as(scot_BNG, "data.frame")
# coercing to a SpatialPointsDataFrame
coordinates(pts) <- c("X_COOR", "Y_COOR")
# coercing the polygon outlines to a SpatialLines object
spl <- list("sp.lines", as(scot_BNG, "SpatialLines"))
# simple bubble plot, see ?bubble for other alternatives
bubble(pts, "SMR", sp.layout=spl)

The sp package contains class definitions for classes to contain spatial 
data, and has methods for coercion and plotting, using both base graphics, 
and, as here, lattice graphics. The first hit on:

RSiteSearch("bubble plot")

is to the help page for bubble() in sp.

Hope this helps,

Roger


>
> Thank you,
>
> Rebecca
>
> (rebecca.ross at plants.ox.ac.uk)
>
> ----- End of forwarded message from Rebecca Ross
> <rebecca.ross at queens.ox.ac.uk> -----
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
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