Home > database >  How to fill empty cells in gpplot2 for absent data
How to fill empty cells in gpplot2 for absent data

Time:10-24

I created this heatmap in R with ggplot2 heatmap

I'd like to add empty tiles borders for the empty observations, but these values are absent in my dataset, which has the following structure :

Shop Day Sales
01 01 4
01 02 2
01 05 3
02 01 1
03 03 2

Any idea please ?

CodePudding user response:

I would create an empty tibble with the structure you need and join in the real data. For example,

fake_dat <- crossing(Shop = 1:3, Day = 1:20)
plot_dat <- left_join(fake_dat, real_dat, by=c("Shop","Day")

ggplot(plot_dat, aes(Day, Shop)) %>%
    geom_tile(color="black") %>%
    geom_label(aes(label=Sales))
  • Related