tags:

views:

97

answers:

1

The following code works well:

p <- ggplot(df,aes(x=x,y=y))
p <- p + geom_tile(aes(fill=z))
p

It plots a nice heatmap. Here df contains x and y, created using expand.grid(), and z which contains the value at each (x,y) co-ordinate.

This code, on the other hand

p <- ggplot(df,aes(x=x,y=y))
p <- p + coord_map(project="lagrange")
p <- p + geom_tile(aes(fill=z))
p

doesn't plot anything much at all (and doesn't plot anything with all the coordinate transforms I've tried). My understanding is that the coord_map works on the x and y data, and the fill should be drawn on top of the transformed co-ordinates. However, this must be wrong as nothing's being plotted once the co-ordinates have been mapped to a new frame.

So my question is: how should I go about this so that it works properly? Could it be something to do with my data.frame df?

A: 

I think the problem is in how the tile geom calculates the area it should cover interacting with the new coordinate system. I tried recreating your problem with this code.

vol.m <- melt(volcano)

#points & cartesian
p <- ggplot(vol.m, aes(X1, X2, color = value)) + geom_point()
#points and map
p + coord_map()

#hex & cartesian
p <- ggplot(vol.m, aes(X1, X2, fill = value)) + geom_hex(stat = "identity")
#hex & map
p + coord_map

I sat there for a while trying the same thing with geom_tile(), but it wouldn't plot, so I'll take your word for it that it doesn't work. Notice how the hexagons get all screwed up on the map coordinates. I guess when trying to plot tiles which have been calculated to fill the area, it can't tolerate plotting them on a different coordinate system.

Edit: That is, changing the coordinate system merely changes the "graph paper" the plot is drawn on. So, if you computed a linear regression statistic, then changed the coordinates to be log-transformed, the plotted regression line would be bent. I'm guessing that ggplot2 can't "bend" a tile to fit into a non-cartesian coordinate system.

JoFrhwld