简体   繁体   English

如何以百分比形式显示关联矩阵

[英]How do I display Correlation matrix as percentage

I am trying to display the correlation labels as a percentage instead of displaying them between the numbers -1 and 1. I was able to do this using the package ggcorrplot , However doing this took away the capability of displaying them with the color pallet and display it with just a grey cell colors. 我试图将相关标签显示为百分比而不是在数字-1和1之间显示它。我能够使用包ggcorrplot来执行此操作。但是这样做会消除使用颜色托盘和显示器显示它们的能力它只有一个灰色的单元格颜色。 This is how it looks like 这就是它的样子

在此输入图像描述

I was able to do this using the package ggcorrplot , However doing this took away the capability of displaying them with the color pallet. 我能够使用ggcorrplot软件包来实现这ggcorrplot ,但这样做会消除使用颜色托盘显示它们的能力。

#if(!require(devtools)) install.packages("devtools")
#devtools::install_github("kassambara/ggcorrplot")
library(ggcorrplot)
corr <- round(cor(test3),3)
corr <- corr * 100
ggcorrplot(corr, hc.order = TRUE, type = "lower",
           lab = TRUE, colors = c("blue", "white", "red"))

Is there way to get the results as a percentage and still have the colors as we normally have in a correlation matrix plot. 有没有办法将结果作为百分比得到,并且仍然具有我们通常在相关矩阵图中的颜色。 Also any way to add percentage to the labels as currently it only displays the number. 也可以通过任何方式向标签添加百分比,因为它只显示数字。

Thanks a lot in advance !! 非常感谢提前!!

corr <- round(cor(mtcars)^2,3)
corr <- corr * 100

diag(corr) = NA
corr[upper.tri(corr)] = NA

library(reshape2)
d = melt(corr)
d = d[!is.na(d$value),]

library(ggplot2)
ggplot(d, aes(x = Var1,
              y = Var2,
              fill = value,
              label = ifelse(is.na(value), "", paste0(value,"%")))) +
    geom_tile(color = "white") +
    scale_fill_gradientn(colors = c("green", "white", "red"), na.value = NA) +
    geom_text() +
    theme_bw()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在散点图中显示相关系数? - How do I display a correlation coefficient in a scatterplot? 如何重新创建相关矩阵以运行 p.adjust? - How do I recreate a correlation matrix to run p.adjust? 如何为时间序列绘制互相关矩阵? - How do I plot a cross correlation matrix for timeseries? 在 R 中,我如何使用 ggplot 将 label 的一部分斜体显示在相关矩阵的某些图块上 - In R, how can I italicize part of a label that I display on only some tiles of a correlation matrix using ggplot 我如何只在相关矩阵中包括大于0.6的相关系数? - How would I only include correlation coefficients above .6 in a correlation matrix? 如何在 R 中创建相关矩阵? - How can I create a correlation matrix in R? 如何在ggplot2的geom_line中显示百分比? - How do I display percentage in geom_line in ggplot2? 如何从具有虚拟变量的数据中找到相关性和协方差矩阵? - How do I find the correlation and the covariance matrix from a data with a dummy variable? R - 如何基于相关矩阵而不是原始数据运行回归? - R - How do I run a regression based on a correlation matrix rather than raw data? 如何打印使用基本 R 的 cor(data) 命令生成的相关矩阵? - How do I print out a correlation matrix produced using basic R's cor(data) command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM