Reputation: 191
I have the data like below:
A B 100
A C 100
B D 80
A D 50
B C 5
B D 60
basically three columns column 1 and Column 2 are character columns and column 3 is an integer which represents percentage of match between Col1 and Col2. Now I would like to represent this data as a correlation matrix. How can I do the same?
Upvotes: 0
Views: 300
Reputation: 19716
Here is an example on how to reconstruct the whole correlation matrix relatively simply using igraph:
library(igraph)
library(corrplot)
g <- graph.data.frame(df, directed = FALSE)
mat <- get.adjacency(g, attr = "V3", sparse = FALSE)
mat
#output
A B C D
A 0 100 100 50
B 100 0 5 60
C 100 5 0 0
D 50 60 0 0
diag(mat) <- 100
mat <- mat/100
corrplot.mixed(mat, upper = "shade", "number")
Upvotes: 2
Reputation: 1847
There is already one answer, but here is an idea with only base functions
heatmap(
xtabs(
data = aggregate(V3 ~ V1 + V2, data, 'mean'),
formula = V3 ~ V1 + V2
),
Rowv = NA,
Colv = NA,
revC = T)
)
Upvotes: 0