I am trying to create a heatmap with ggplots
geom_tile
. As it stands the grid lines are centered at the middle of each geom_tile
. What I want is the gridlines to be aligned with the start/end of each tile. I have seen a few related posts (here, here, but all are dealing with continuous scales. In my case, both scales are discrete/factors. Any idea? Many thanks!
library(tidyverse)
my_iris <- iris %>%
mutate(sepal_interval=cut(Sepal.Length, 4)) %>%
group_by(sepal_interval, Species)
my_iris %>%
summarise(n_obs=n()) %>%
ggplot()+
geom_tile(aes(y=Species,
x=sepal_interval,
fill=n_obs))+
theme_bw()+
theme(panel.grid = element_line(color="black"))
Created on 2020-01-28 by the reprex package (v0.3.0)