I'm using qgraph to plot a network graph from a distance matrix and I can't get the labels to match the colours of the nodes in the graph.
My code is as follows:
clr <- function(x) {
known <- c(`Effluent`="seagreen", `Influent`="brown", `WWTP Animal`="skyblue",
`Human`="red", `Aircraft`="lemonchiffon")
known[x]
}
x <- read.table("Path/to/distance/matrix.tsv", sep="\t", header = T)
x <- 1 / as.matrix(x[,-1])
x_sub <- x[1:50,1:50]
grps <- data[,c("ID","Sample_type_grouped")]
grps <- grps[grps$ID %in% colnames(x_sub),]
grps <- grps[match(colnames(x_sub),grps[,"ID"]),"Sample_type_grouped"]
qgraph(x_sub, layout='spring', groups=grps, color=clr(grps))
Thanks for any help!