简体   繁体   English

相关矩阵的和弦图。 电阻

[英]Chord Plot for a Correlation matrix. R

I want to create a Chord plot for a correlation matrix.我想为相关矩阵创建和弦图。 Where the links represent the correlations in a color gradient from -1 to 1 (blue to red).其中链接表示从 -1 到 1(蓝色到红色)的颜色渐变中的相关性。 I want just to represent those links that have an actual correlation.我只想代表那些具有实际相关性的链接。

This is an example dataset:这是一个示例数据集:

c1<-c(0,0,0.5,-0.2,0.1,-0.8)
c2<-c(0.2,0.8,-0.5,0,0,0)
c3<-c(0,0,-0.2,0,0,0.1)
mat<-rbind(c1,c2,c3)
rownames(mat) = paste0("S", 1:3)
colnames(mat) = paste0("E", 1:6)
df = data.frame(from = rep(rownames(mat), times = ncol(mat)),
                to = rep(colnames(mat), each = nrow(mat)),
                value = as.vector(mat),
                stringsAsFactors = FALSE)

A simple way to represent this in a chord plot would be like:在和弦图中表示这一点的简单方法如下:

windows()
chordDiagram(df, big.gap = 30)
circos.clear()

However, it represents all the links, even if the value is 0. How can I create a color gradient for the value, from -1 to 1 with the 0 being white?但是,它代表所有链接,即使值为 0。如何为该值创建颜色渐变,从 -1 到 1,0 为白色?

Thanks谢谢

Assuming you are using the circlize package you can adjust the colours manually based on a range by writing a function and then inputting it in the col argument of the chordDiagram() function:假设您使用的是circlize包,您可以通过编写函数然后将其输入到chordDiagram()函数的col参数中,根据范围手动调整颜色:

library(circlize)
cols = colorRamp2(c(-1,0,1),c("blue","white","red"),transparency = 0.3)
chordDiagram(mat,col=cols,big.gap=30)

I used the matrix to plot the chord diagram but the data frame should produce the same results.我使用矩阵来绘制和弦图,但数据框应该产生相同的结果。 However, I don't understand what you mean when you say all links are represented even if the value is 0 since for example, S1 to E1 is 0 but there is no link between the two但是,当您说即使值为 0 也表示所有链接时,我不明白您的意思,因为例如,S1 到 E1 为 0 但两者之间没有链接在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM