geom_raster interpolation with log scale

Viewed 2146

I'm a bit stuck plotting a raster with a log scale. Consider this plot for example:

ggplot(faithfuld, aes(waiting, eruptions)) +
 geom_raster(aes(fill = density))

enter image description here

But how to use a log scale with this geom? None of the usual methods are very satisfying:

 ggplot(faithfuld, aes(waiting, log10(eruptions))) +
   geom_raster(aes(fill = density))

enter image description here

 ggplot(faithfuld, aes(waiting, (eruptions))) +
   geom_raster(aes(fill = density)) + 
   scale_y_log10()

enter image description here

and this doesn't work at all:

 ggplot(faithfuld, aes(waiting, (eruptions))) +
   geom_raster(aes(fill = density)) + 
   coord_trans(x="log10")

Error: geom_raster only works with Cartesian coordinates

Are there any options for using a log scale with a raster?

To be precise, I have three columns of data. The z value is the one I want to use to colour the raster, and it is not computed from the x and y values. So I need to supply all three columns to the ggplot function. For example:

dat <- data.frame(x = rep(1:10, 10), 
                  y = unlist(lapply(1:10, function(i) rep(i, 10))), 
                  z = faithfuld$density[1:100])

ggplot(dat, aes(x = log(x), y = y, fill = z)) +
  geom_raster()

enter image description here

What can I do to get rid of those gaps in the raster?

Note that this question is related to these two:

I have been keeping an updated gist of R code that combines details from the answers to these questions (example output included in the gist). That gist is here: https://gist.github.com/benmarwick/9a54cbd325149a8ff405

1 Answers
Related