Hi Thank you for reading and potential help!
I am trying to annotate the x and y-axis of a corelation heatmap generated using ggplot with the following code:
# Gen ggplot
ggplot(cor.df, aes(x, y, fill = correlation)) +
geom_tile(#color = "black") + theme_bw() + theme(axis.text.x = element_text(angle=70,vjust = 1, hjust=1)) + scale_fill_gradient2(low = "dodgerblue4", high = "red4", mid = "white",
midpoint = 0.5, limit = c(0,1), space = "Lab",
name="Pearson\nCorrelation")
The x and y-axis however are cells with a variety of metadata, such as origin, disease, celltype etc (for the sake of brevity say that these 3 metadata types exist).
cor.df above is a dataframe:
# Example dat:
x y correlation
1 cell1_disease1_origin1 cell1_disease1_origin1 0.5
2 cell2_disease1_origin1 cell2_disease1_origin1 0.5
3 cell3_disease1_origin2 cell3_disease1_origin2 0.5
4 cell4_disease2_origin2 cell4_disease2_origin2 0.5
5 cell5_disease2_origin3 cell5_disease2_origin3 0.5
The goal is to add some coding to the ggplot object so that annotation bars can be added on the x and y axis, for example what you observe on the y-axis here:
OR something like what is shown here:
heatmap with annotations on x and y axis
But instead of just one annotation, I want 3 annotation labels stacked on one another for the 3 types of metadata. I understand that metadata can be added to cor.df and then perhaps the link between metadata and plotting data can be used to A. Create the heatmap and then B the layers of annotation bars on the y and x axis?
I apologize in advance if this is not reprex enough.....feel free to destroy me if its not....thank you for the help!
P.S no not looking to use complexheatmap or heatmap, I want to learn solutions with native ggplot verbs because thats the best way honestly to learn and implement other ideas rather than forever navigate packages (which no doubt can be useful).
Thanks a million!!!
Already tried facet_wrap() and annotation that didnt work.....
