How to use pheatmap in R to draw a box outside a pheatmap plot and save them together

15 Views Asked by At
library(pheatmap)
p<-pheatmap(matrix(rnorm(100,0,1),10,10),
         cluster_rows = F,
         cluster_cols = F,
         cellwidth = 20,
         cellheight = 15)
p
plot(NULL, axes = FALSE, xlab = "", ylab = "", xlim = c(0, 2.5), ylim = c(0, 1))
rect(xleft = 0.635, xright = 1.6, ybottom = 0.18, ytop = 0.775)
p
rect(xleft = 0.635, xright = 1.6, ybottom = 0.18, ytop = 0.775)

ggsave(p,filename = paste0("test","_",format(Sys.Date(), format = "%m_%d"),".pdf"),width =6,height = 6,dpi = 1200)

I want to produce a heatmap by pheatmap in R and add a box alongside the heatmap margin.

I tried several methods just like the above script but failed.

The key point is that I also want to save it through ggsave after the box produced.

Hope somebody give some help on this question.

Thanks in advance.

0

There are 0 best solutions below