I'm trying to recreate the "Clustergram" from enrichR (reproduced below)
The part I'm missing are the bars that overlayed on the x-axis labels on top which correspond to the "combined score" from enrichR. Is there some way for me to recreate this in ggplot? TIA!
Here is what I have so far, using patchwork. I'm not sure how to get angle my bars and get the labels to line up properly?
library(ggplot2)
library(patchwork)
gene.dat = data.frame(Term = c(rep("Diseases Of Base Excision Repair", 7), rep("HDR Thru Homologous Recombination (HRR)", 7)),
Genes = c(rep(c("A", "B", "C", "D", "E", "F", "G"), 2)),
n = c(NA, 1, NA, NA, 1, 1, 1,
1, NA, 1, 1, NA, NA, 1))
scores.dat = data.frame(Term = c("HDR Thru Homologous Recombination (HRR)", "Diseases Of Base Excision Repair"),
Combined.Score = c(5329, 2738))
main.plot = ggplot(gene.dat, aes(Term, Genes)) +
geom_tile(aes(fill = n))+
theme(
plot.title = element_text(hjust = 1),
#The line below is for my original x axis labels - with patchwork
#I'm leaving this blank and letting the score_plot have the labels?
#axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=0, size =16, color = 'black'),
axis.text.x = element_blank(),
legend.position="none",
panel.background = element_blank()) +
ylab("") + xlab("") +
scale_x_discrete(position = "top")
score.plot = ggplot(scores.dat, aes(Term, Combined.Score)) +
geom_col() +
geom_text(aes(label = Term), angle = 90, hjust = 0.5) +
theme_void()
Y <- (score.plot + main.plot) +
plot_layout(ncol = 1, nrow = 2, heights = c(1, 3), widths = c(2.75, 1))