An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20071102/ae0029f9/attachment.pl>
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 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
Felix Andrews / ??? PhD candidate Integrated Catchment Assessment and Management Centre The Fenner School of Environment and Society The Australian National University (Building 48A), ACT 0200 Beijing Bag, Locked Bag 40, Kingston ACT 2604 http://www.neurofractal.org/felix/ 3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8
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