[R-sig-Geo] Add coastline to an existing xyplot [SEC=UNCLASSIFIED]
hiemstra at geo.uu.nl
hiemstra at geo.uu.nl
Sat Nov 3 01:20:26 CET 2007
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:
> Hi there,
> I tried to add a coastline that is imported from a shapefile to a xyplot
of
> sample points, but I got an error message.
>
>
>> library(lattice)
>>
>
>> library(maptools)
>>
>
>> xyplot(mud$lat~mud$long, asp="iso", type="p", pch=1, cex=0.01, xlab="",
>>
> ylab="")
>
>
>> plot(coastline, add=T)
>>
> Error in plot.xy(xy.coords(x, y), type = type, ...) :
> plot.new has not been called yet
>
> I also tried using plot.new=TRUE in the xyplot and got the same message.
>
> I could get a plot from only using plot(coastline), but could not add
it to
> the existing xyplot.
>
> Thanks in advance.
> Jin
>
> [[alternative HTML version deleted]]
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list