Re: How to plot polygon (SpatialPolygonsDataFrame) over the raster map

443 views
Skip to the first unread message

Brian

unread,
30 Sept 2015, 13:12:5330/09/2015
to Vivian Ribeiro, ggplot2
Dear Vivian,

you're going to have to learn the ggplot concepts (and forget the
typical R plotting concepts) to arrive at a solution.

For a very nice example of using spatial data see:
https://groups.google.com/d/msg/ggplot2/sws5bHurcpw/SvgONn2ZFAAJ

adding a raster layer would be pretty easy

rasterdata = as.data.frame(SpatialPixelsDataFrameObject)
# in which the default xy-coordinate names are "s1" and "s2", and there
is a column named "value" i.e. "value" %in% names(rasterdata)
gg + geom_raster(data=rasterdata, aes(s1, s2, fill=value))

I hope that helps.

Cheers,
Brian

On 30.09.2015 13:48, Vivian Ribeiro wrote:
> Hi everyone,
> I'm trying to create a map using a raster layer and
> SpatialPolygonsDataFrame. When you are using the function plot this
> could be very simple, you just need to use the argument add=T but I
> can't do the same thing in ggplot package. I plotted the shape and the
> raster independently, but when I use the signal + the R gives me this
> answer: Error in the p +: non-numeric argument for binary operator
> What I did wrong?
>
> All the best
> --
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google
> Groups "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ggplot2+u...@googlegroups.com
> <mailto:ggplot2+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages