2

I'm plotting a correlation plot with 10 variables using method="number." I'm trying to export the plot with large font sizes (number.cex = 3, tl.cex = 3) for publication purposes, but the squares do not increase in size to accommodate the larger fonts. Is there a way to modify this?

This is my code if it helps:

corrplot(as.matrix(K), tl.cex = 3, tl.col = "black", method = "color", 
         outline = T,  order="hclust", 
         addCoef.col = "black", number.digits = 2, number.cex = 3, 
         cl.pos = 'b', cl.cex = 3, addrect = 3, rect.lwd = 3, 
         col = colorRampPalette(c("midnightblue", "white","darkred"))(100))
G5W
  • 36,531
  • 10
  • 47
  • 80
bashmike
  • 73
  • 1
  • 2
  • 8

2 Answers2

4

You should tune the width, height and res parameters of your graphic output file.
See an example below.

set.seed(1)
X = matrix(runif(1000),ncol=10)
library(corrplot)
png(file="corr.png", res=300, width=4500, height=4500)
corrplot(as.matrix(cor(X)), tl.cex = 3, tl.col = "black", method = "color", 
         outline = T,  order="hclust", 
         addCoef.col = "black", number.digits = 2, number.cex = 3, 
         cl.pos = 'b', cl.cex = 3, addrect = 3, rect.lwd = 3, 
         col = colorRampPalette(c("midnightblue", "white","darkred"))(100))
dev.off()

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • POssibly a dumb question....but why is the plot not showing up when using png(file="corr.png", res=300, width=4500, height=4500)....moreover how do I save the plot than? – H. berg May 05 '21 at 14:20
  • Sorry i had to use dev.off()....but still I dont get what the png(file="corr.png", res=300, width=4500, height=4500) does before calling the plot...I dont see how it changes the plot – H. berg May 07 '21 at 19:11
  • 1
    @H.berg `png(file="corr.png", res=300, width=4500, height=4500)` redirects the output of the plot command (the graph) into a file in a png format. Try `?Devices`. You can see the list of available graphic devices. – Marco Sandri May 07 '21 at 20:44
1

Might be a really stupid idea, but depending on what version of R you use, you could simply go to full screen with the window that pops up once you run your corrplot() function. That has worked for me in the past. And then I guess you should make sure to choose the right format; TIFF for instance.

The more sophisticated solution would be this of course. Here the idea is to adjust the figure parameters once you write it/ save it. Does that make sense?

Generally, the idea is something like this (with interchangable format types):

tiff(filename=".tiff",width=...,height=...,res=...)

or

jpeg()

The packages you can try for that are {grDevices} or {tiff} and there are certainly hundreds more. ;)

Let me know if that worked out for you.

Cheers!

Dr. Fabian Habersack
  • 1,111
  • 12
  • 30
  • Also, I learned that questions should contain a reproducible example (see [here](https://stackoverflow.com/help/on-topic), and [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)). To me that made sense because it makes it easier for others to respond and for you to get useful advice, right? But I'm myself still learning how this stuff works on stackoverflow ;) – Dr. Fabian Habersack Aug 04 '17 at 20:22