Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)

I have a matrix with some correlation values. Now I want to plot that in a graph that looks more or less like that:

enter image description here

1 Answer

0 votes
by
edited by

To plot a correlation matrix on a graph, you can use the lattice package as follows:

To create the information for the horizontal and vertical axis.

library(lattice)

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

vert <- paste("DM1-", hori, sep="")

To build a dummy correlation matrix

nrowcol <- length(vert)

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

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

To plot the matrix

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))

Output:

image

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...