Raster* objects can be directly manipulated by ggplot2 (yet?).
You need to convert your Raster object ito a data.frame first, then
plot it using geom_tile().
Note that this would be very inefficient - or even impossible - with a
big raster, as it is vector graphics.
Consider the following example (please always provide with a
reproducible example):
library(raster)
data(meuse.grid)
coordinates(meuse.grid) = ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) = TRUE
r <- raster(meuse.grid, layer=5)
r
# To convert your RasterLayer to a data.frame, you need to convert it to
# a SpatialPixelsDataFrame first
r.spdf <- as(r, "SpatialPixelsDataFrame")
r.df <- as.data.frame(r.spdf)
head(r.df)
# then you can use ggplot2 to plot that object
library(ggplot2)
g <- ggplot(r.df, aes(x=x, y=y)) + geom_tile(aes(fill = V1)) + coord_equal()
print(g)
HTH,
Pierre
2011/7/16 Swagath <swagat...@gmail.com>:
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Scientist
Landcare Research, New Zealand