Skip to content

Add coastline to an existing xyplot [SEC=UNCLASSIFIED]

3 messages · Li Jin, Felix Andrews, hiemstra at geo.uu.nl

#
plot() is a base graphics function. You can not use it in a Lattice
context. And also you can not add to a Lattice plot as you tried to
do: you need to use a panel function, or call trellis.focus(). I
suggest you read the Lattice documentation.

This is one way to do it:

library(sp)

xyplot(lat ~ long, data=mud, panel=function(...) {
sp.polygons(coastline)
panel.xyplot(...)
},
asp="iso", type="p", pch=1, cex=0.01, xlab="", ylab="")
On 11/2/07, Jin.Li at ga.gov.au <Jin.Li at ga.gov.au> wrote:

  
    
#
Hi,

You could use the function spplot in the sp-pacakge. Use the sp.layout 
argument to add the shapefile to the plot. All the data needs to be in 
one of the Spatial classes provided by the sp-package. The code could 
look something like:

library(sp)
library(maptools)
points = read.table("points.csv")
coordinates(points) = ~x+y
shape_coast = readShapePoly("coast.shp") # Function from maptools
spplot(points, "attribute1", sp.layout = list("sp.polygons", shape_coast))
?spplot

hth,
Paul
Jin.Li at ga.gov.au wrote:
of
it to