Skip to content

Instantly share code, notes, and snippets.

@pierreroudier
Created December 2, 2011 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierreroudier/1421105 to your computer and use it in GitHub Desktop.
Save pierreroudier/1421105 to your computer and use it in GitHub Desktop.
Bug in geom_raster?
# I've been testing Hadley's last dev version of ggplot2 - my interest being mainly triggered
# by the new and shiny geom_raster(), as I'm still convinced a mapping framework based on
# ggplot2 would just be awesome to see (fast and easy production of very nice looking maps).
#
# Somehow I managed to test it using a simple coercition of the SpatialPixelsDataFrame objects
# into data.frames, but for some reasons it seems to be handling the coordinates on a weird way.
#
# Is that a bug?
#
library(sp)
# Loading demo data
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) <- TRUE
# Reference plot
spplot(muse.grid, zcol = "dist")
# Coercition into data.frame
mgdf <- as.data.frame(meuse.grid)
head(mgdf)
# ggplot2 plot
ggplot(mgdf, aes(x = x, y = y)) + geom_raster(aes(fill = dist))
# Looking into the coordinates of mgdf to check this is not as.data.frame()
plot(mgdf$x, mgdf$y, pch = "+", asp = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment