Reputation: 13443
Using ggplot2 geom_tile, the default location of the tiles is centred on values of x and y. Is there a way to get x and y values to be the bottom left corner of each tile.
From http://docs.ggplot2.org/current/geom_tile.html
x.cell.boundary <- c(0, 4, 6, 8, 10, 14)
example <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 2),
y = factor(rep(c(1,2), each=5)),
z = rep(1:5, each=2),
w = rep(diff(x.cell.boundary), 2)
)
qplot(x, y, fill=z, data=example, geom="tile")
Upvotes: 0
Views: 552
Reputation: 6197
I do not like my answer, but I'll post it anyway while waiting for a better solution. I transform the data (x-axis +1 and y-axis +0.5) and use the real data as axis breaks.
example <- data.frame( x = rep(c(3, 6, 8, 10, 13), 2), y = (rep(c(1.5,2.5), each=5)), z = rep(1:5, each=2))
ggplot(example)+ geom_tile(aes(x,y,fill=z)) +
scale_x_continuous(breaks=c(2, 5, 7, 9, 12))+
scale_y_continuous(breaks=c(1,2))
Upvotes: 1