Plot of a correlation matrix in R like in Excel example

后端 未结 3 1191
执笔经年
执笔经年 2021-02-03 15:21

I have been trying to minimize my use of Excel in favor of R, but am still stuck when it comes to display simple data cells as is often needed as the last step of an analysis. T

3条回答
  •  醉梦人生
    2021-02-03 15:30

    Your correlation matrix has several values greater than 1, which is not possible. But anyhow...

    Try this one

    library(reshape2)
    dat <- melt(cor_matrix[-11, ])
    
    library(ggplot2)
    p <- ggplot(data =  dat, aes(x = Var1, y = Var2)) +
      geom_tile(aes(fill = value), colour = "white") +
      geom_text(aes(label = sprintf("%1.2f",value)), vjust = 1) +
      scale_fill_gradient(low = "white", high = "steelblue")
    

    print(p)

    enter image description here

提交回复
热议问题