(R) - Colorkey of Heatmap.2 is taking too long to load in PDF

283 Views Asked by At

I am trying to create a heatmap for a data set that contains 4 columns and 600 rows. I am using the heatmap.2 function and creating the file using the pdf() function. If I create the heatmap without the Color Key it opens quickly; however, if I add the Color Key it takes a while to fully load it and I don't know why. It doesn't necessarily impact the final image, but if I try to load it into Adobe Illustrator it crashes.

The file with and without the color key is 436 KB and 70 KB, respectively. As I am using color breaks I decided to lower the number to see if it would help, but no success. I also tried to lower the size of the color key using the keysize argument, but also no success.

My code is the following:

data <- read.csv("C:/Users/proteomics.csv")
rnames <- data[,1]
mat_data <- data.matrix(data[,2:ncol(data)])
row.names(mat_data) <- rnames

my_palette <- colorRampPalette(c("blue", "white", "red"))(n = 299)

col_breaks = c(seq(min(mat_data),-0.833,length=100),  # for Blue
               seq(-0.832,0.794,length=100),           # for White
               seq(0.795,max(mat_data),length=100))             # for Red

pdf("C:/Users/file.pdf",
    paper = "letter", height = 10, useDingbats=FALSE)
heatmap.2(mat_data,
          #cellnote = mat_data,  # same data set for cell labels
          main = "Proteomics", # heat map title
          notecol="black",      # change font color of cell labels to black
          density.info="none",  # turns off density plot inside color legend
          trace="none",         # turns off trace lines inside the heat map
          margins =c(4,3),     # widens margins around plot
          col=my_palette,       # use on color palette defined earlier
          breaks=col_breaks,   # enable color transition at specified limits
          dendrogram="none",     # only draw a row dendrogram
          #scale = "row",
          labRow = FALSE,
          Rowv = FALSE,         # Row clustering
          srtCol=45,            # Column text angle
          key=T, cexRow = 0.2, cexCol=1, 
          lhei=c(3,22), lwid=c(3,8),
          keysize=0.25,
          #key.par = list(cex=0.1),
          Colv="NA")            # turn off column clustering            # turn off column clustering

dev.off()

It feels that the color key is adding way to much information in the final file. Is there anyway to reduce it? In theory it should open in pdf quicker and allow me to load it into Illustrator.

0

There are 0 best solutions below