I have a dataframe df
with nodes information like below:
dput(df)
structure(list(Names = c("A4GALT", "AASS", "ABCA10", "ABCA7",
"ABCD4", "ABHD4", "ABTB1", "AC006978.2", "AC009119.2"), type = c("typeA",
"typeA", "typeC", "typeA", "typeC", "typeC", "typeB", "typeB",
"typeB"), type_num = c(1L, 1L, 3L, 1L, 3L, 3L, 2L, 2L, 2L), Clusters = c("Cluster1",
"Cluster1", "Cluster2", "Cluster3", "Cluster3", "Cluster1", "Cluster2",
"Cluster3", "Cluster2")), row.names = c(NA, 9L), class = "data.frame")
So, in the df
dataframe, there are 4 columns. Names
is the gene name, type
is different types A, B and C, type_num
is the number given to each type and column Clusters
show 3 clusters in which each gene belong to.
Similarly, I have other dataframe df2
with with edges information. And below I’m showing that:
dput(df2)
structure(list(fromNode = c("A4GALT", "A4GALT", "A4GALT", "A4GALT",
"A4GALT", "A4GALT", "A4GALT", "A4GALT", "AASS", "AASS", "AASS",
"AASS", "AASS", "AASS", "AASS", "ABCA10", "ABCA10", "ABCA10",
"ABCA10", "ABCA10", "ABCA10", "ABCA7", "ABCA7", "ABCA7", "ABCA7",
"ABCA7", "ABCD4", "ABCD4", "ABCD4", "ABCD4", "ABHD4", "ABHD4",
"ABHD4", "ABTB1", "ABTB1", "AC006978.2"), toNode = c("AASS",
"ABCA10", "ABCA7", "ABCD4", "ABHD4", "ABTB1", "AC006978.2", "AC009119.2",
"ABCA10", "ABCA7", "ABCD4", "ABHD4", "ABTB1", "AC006978.2", "AC009119.2",
"ABCA7", "ABCD4", "ABHD4", "ABTB1", "AC006978.2", "AC009119.2",
"ABCD4", "ABHD4", "ABTB1", "AC006978.2", "AC009119.2", "ABHD4",
"ABTB1", "AC006978.2", "AC009119.2", "ABTB1", "AC006978.2", "AC009119.2",
"AC006978.2", "AC009119.2", "AC009119.2"), weight = c(0.005842835,
0.002253695, 0.014513253, 0.004851739, 0.066702792, 0.009418991,
0.001136938, 0.000474221, 0.004405601, 0.000666001, 0.005625977,
0.0333554, 0.004666223, 0.000103131, 0.00026302, 0.004514819,
0.029632695, 0.001825839, 0.028379806, 0.001403298, 0.008339397,
0.02393394, 0.004782329, 0.024767355, 0.002986813, 0.00559471,
0.005961539, 0.064831874, 0.013023138, 0.027935729, 0.006618816,
0.001134219, 0.012798368, 0.007961242, 0.01640476, 0.007997743
), direction = c("undirected", "undirected", "undirected", "undirected",
"undirected", "undirected", "undirected", "undirected", "undirected",
"undirected", "undirected", "undirected", "undirected", "undirected",
"undirected", "undirected", "undirected", "undirected", "undirected",
"undirected", "undirected", "undirected", "undirected", "undirected",
"undirected", "undirected", "undirected", "undirected", "undirected",
"undirected", "undirected", "undirected", "undirected", "undirected",
"undirected", "undirected")), row.names = c(NA, -36L), class = "data.frame")
I wanted to create a network like below which represents the clusters with types having different colors in each cluster. It should look something like this:
In the above image the numbers represent different clusters and colors represent different types which belong to each cluster and connected.
Can anyone please help me how to create a network like above to collapse each cluster into a single network node and visualize a network with clusters as nodes. Any help is appreciated. thank you in advance.