为了账号安全,请及时绑定邮箱和手机立即绑定

将相关矩阵绘制成图

将相关矩阵绘制成图

千巷猫影 2019-12-09 09:53:56
我有一些相关值的矩阵。现在,我想在一个看起来或多或少像这样的图形中绘制该图形:我该如何实现?
查看完整描述

3 回答

?
慕容森

TA贡献1853条经验 获得超18个赞


library(lattice)


#Build the horizontal and vertical axis information

hor <- c("214", "215", "216", "224", "211", "212", "213", "223", "226", "225")

ver <- paste("DM1-", hor, sep="")


#Build the fake correlation matrix

nrowcol <- length(ver)

cor <- matrix(runif(nrowcol*nrowcol, min=0.4), nrow=nrowcol, ncol=nrowcol, dimnames = list(hor, ver))

for (i in 1:nrowcol) cor[i,i] = 1


#Build the plot

rgb.palette <- colorRampPalette(c("blue", "yellow"), space = "rgb")

levelplot(cor, main="stage 12-14 array correlation matrix", xlab="", ylab="", col.regions=rgb.palette(120), cuts=100, at=seq(0,1,0.01))


查看完整回答
反对 回复 2019-12-09
?
一只名叫tom的猫

TA贡献1906条经验 获得超2个赞

非常容易使用grid :: levelplot:


z <- cor(mtcars)

require(lattice)

levelplot(z)


查看完整回答
反对 回复 2019-12-09
?
三国纷争

TA贡献1804条经验 获得超7个赞

ggplot2库可以使用来处理此问题geom_tile()。由于没有任何负相关,因此上图中似乎已进行了一些缩放,因此请在数据中考虑这一点。使用mtcars数据集:


library(ggplot2)

library(reshape)


z <- cor(mtcars)

z.m <- melt(z)


ggplot(z.m, aes(X1, X2, fill = value)) + geom_tile() + 

scale_fill_gradient(low = "blue",  high = "yellow")


编辑:


ggplot(z.m, aes(X1, X2, fill = value)) + geom_tile() + 

scale_fill_gradient2(low = "blue",  high = "yellow")


允许指定中点的颜色,默认为白色,因此此处可能是一个不错的调整。其他选项可以在ggplot网站的此处和此处找到。


查看完整回答
反对 回复 2019-12-09
  • 3 回答
  • 0 关注
  • 470 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信