How can I mirror a heatmap figure in R?

246 Views Asked by At

I am using the ggcorrplot package in R to make a heatmap figure. My code is:

allrg <- ggcorrplot(mat_allrg, hc.order = TRUE, type = "lower",lab = TRUE, legend.title = "rG", ggtheme = ggplot2::theme_void,
           outline.col = "white", colors=c("#4477AA", "#FFFFFF", "#BB4444"))

Which generates the following figure.

This is my figure

I would like to mirror this plot to have an orientation from the left to right to have the y labels closer. This package uses ggplot2, so I was able to add functions using ggplot2, e.g.,

allrg + guides(fill=guide_colourbar(barwidth = 1, barheight = 20))

The orientation I would like to have including having the x and y axis labels adjusted as in the figure: enter image description here

I have tried coord_flip() and scale_y_reverse() but they did not work.

Also, although I set digits=2, when the next 1 or 2 digits are 0 in the dataset, the figure does not show the 0s. I tried sprintf but the figure still does not show the 0s.

1

There are 1 best solutions below

2
On

You could use the limit argument in scale_x_discrete(), e.g.:

ggcorrplot(corr, type = "lower", outline.col = "white") +
 scale_x_discrete(limits=rev(colnames(corr)[2:11]))

(w.r.t your code I removed the hc.order = TRUE for simplicity.