Search code examples
rplotcorrelationr-corrplot

CorrPlot fails to Generate heatmap in R


I want to know how to plot a 1000x1000 correlation plot in R using corrplot library.

My Try:

a <- replicate(1000, rnorm(1000)) 
library('corrplot')
png("Correlation_plot.png")
corrplot(cor(a))
dev.off()

Try 2:

a <- replicate(1000, rnorm(1000)) 
png("Correlation_plot.png")
heatmap(cor(a))
dev.off()

Try 3:

library(ggplot2)
library(reshape2)
co <- cor(a)
mco <- melt(co)
png("Correlation_plot.png")
qplot(x=Var1, y=Var2, data = mco)
dev.off()

Solution

  •                     It is not blank @Devashish Das
    

    So the problem is not with corrplot but with the number of points you are going to plot. In your case also the plot was being drawn but was not visible.

    Here is your code modified which plots the graph with fair visibility.

    i = 1000
    a <- replicate(i, rnorm(i))
    png(paste(i,".png"), width = 3200, height = 3200,units = "px",pointsize = 4)
    corrplot(cor(a),method = "color")
    dev.off()
    

    I tried like this for confirming that the plot is very faintly present

    i = 100
    while(i<1001)
    {
        a <- replicate(i, rnorm(i)) 
        png(paste(i,".png"), width = 3200, height = 3200,units = "px",pointsize = 4)
        corrplot(cor(a),method = "color")
        dev.off()
        print(i)
        i=i+100
    }
    

    Here are some results 100100

    400400

    700700

    10001000