简体   繁体   中英

How can I mirror a heatmap figure in R?

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.

这是我的身影

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, eg,

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: 在此处输入图像描述

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.

You could use the limit argument in scale_x_discrete() , eg:

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

(wrt your code I removed the hc.order = TRUE for simplicity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM