I have a matrix of group distances G
as follows
G <- data.frame( Gp1=c(6.525,15.915,16.605,10.665,19.345), Gp2=c(15.915,8.605,31.455,25.485,48.355), Gp3=c(16.605,31.455,7.955,11.195,33.685), Gp4=c(10.665,25.485,11.195,0,21.985), Gp5=c(19.345,48.355,33.685,21.985,0))
rownames(G) <- colnames(G)
G
Gp1 Gp2 Gp3 Gp4 Gp5
Gp1 6.525 15.915 16.605 10.665 19.345
Gp2 15.915 8.605 31.455 25.485 48.355
Gp3 16.605 31.455 7.955 11.195 33.685
Gp4 10.665 25.485 11.195 0.000 21.985
Gp5 19.345 48.355 33.685 21.985 0.000
The diagonal is the within group distances.
I would like to depict the above in a plot as follows. It need not be to scale to the distance values. How to produce it in R
?
This comes pretty close:
[Note: Incorporated @Jealie's suggestion and made a few other changes. It's a bit closer to your intended result now.]
rownames(G) <- colnames(G) <- c("I","II","III","IV","V")
G[lower.tri(G)] <- 0
library(igraph)
g <- graph.adjacency(as.matrix(G),weight=T, mode="undirected")
g <- simplify(g,remove.loops=TRUE)
plot(g,edge.label=E(g)$weight,
vertex.label=paste(V(g)$name,diag(as.matrix(G)),sep="\n"),
layout=layout.circle,
vertex.size=30)
I'm not aware of a way to make the edge labels parallel to the edges, but that doesn't mean it cant' be done...
Got the solution using qgraph
G <- data.frame( Gp1=c(6.525,15.915,16.605,10.665,19.345), Gp2=c(15.915,8.605,31.455,25.485,48.355), Gp3=c(16.605,31.455,7.955,11.195,33.685), Gp4=c(10.665,25.485,11.195,0,21.985), Gp5=c(19.345,48.355,33.685,21.985,0))
rownames(G) <- colnames(G)
rownames(G) <- colnames(G) <- as.character(as.roman(seq(length.out=nrow(G))))
qgraph(G, layout = "circle", usePCH = TRUE,
normalise = TRUE,
vsize = 7, color = "gray90", node.width = 1,
border.width = 1.7, diag = FALSE,
label.prop = 0.6,
labels = paste(rownames(G),diag(as.matrix(G)),sep="\n"),
esize = 1, edge.labels = TRUE, edge.color = "black", fade=FALSE,
lty = "dotted", edge.label.cex = 0.7, edge.label.bg = "white",
directed = TRUE, arrows = FALSE, bidirectional = TRUE,
asize = 1.5, weighted = FALSE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With