[英]How to fill empty cells in gpplot2 for absent data
I created this heatmap in R with ggplot2 heatmap我用 ggplot2 heatmap 在 R 中创建了这个热图
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 ?有什么想法吗?
I would create an empty tibble with the structure you need and join in the real data.我会用你需要的结构创建一个空的 tibble 并加入真实数据。 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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.