I would like to generate a heatmap with specific cells having an overlaid strikethrough, or some other simple pattern on the cell. I would like to achieve the same results as in this question (ggplot2 geom_tile diagonal line overlay) however I am not able to reproduce this solution, as I am very much struggling to follow the solution's code after geom_segment()
.
Here's some example data for a data frame:
GN a b
willy -1.58215 -2.53036
wee 0.611129 0.485053
waffy 1.580719 0.857198
and the code for the heatmap:
library(tidyr)
library(ggplot2)
legend_title <- "log(z/w)"
pivot_longer(df, 2:3) %>%
ggplot(aes(name, GN, fill=value)) +
geom_tile(color = 'black') +
scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
coord_equal() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_text(color = 'black', face = 'bold')) +
scale_fill_gradient2(legend_title, low = "blue", mid = "white", high = "red")
This should produce the following heatmap:
I would like to be able to specify, for example, the left cell of row waffy and the right cell of wee to be stricken through. It would be even better if there are design options for this, for example having three colored diagonal strikethroughs.
Many thanks for any help.