Weighted edges in R / igraph
I am using R and a package igraph
to plot a graph written in a graph and I want to use the parameter weight
included in this syntax
<edge id="e389" source="w4" target="w0">
<data key="d1">0.166666666667</data>
</edge>
I can get the values with
weight = E(f)$weight // f is the graph
but i dont know how to use weight
before calculatingdf = degree(f)
For more information: all nodes are connected to each other and the weight is 1 / (number_of_nodes - 1), so the degree for each node should be 1.
graphic file
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="label" attr.type="string"/>
<key id="d1" for="edge" attr.name="weight" attr.type="float"/>
<key id="d2" for="node" attr.name="type" attr.type="string"/>
<key id="d3" for="node" attr.name="tweet" attr.type="int"/>
<key id="d4" for="node" attr.name="color" attr.type="string"/>
<graph id="G" edgedefault="undirected">
<node id="w4">
<data key="d0">value1</data>
<data key="d2">word</data>
<data key="d1">0.166666666667</data>
<data key="d4">green</data>
</node>
.
.
.
<node id="w2">
<data key="d0">value2</data>
<data key="d2">word</data>
<data key="d1">0.166666666667</data>
<data key="d4">green</data>
</node>
<edge id="e389" source="w4" target="w0">
<data key="d1">0.166666666667</data>
</edge>
source to share
Chances are you aren't looking degree()
because it doesn't care about the weights of the edges. Are you looking for a feature graph.strength()
?
# create fully connected graph
g <- graph.full(10)
# assign weights such that every weight is 1/number_of_nodes -1
E(g)$weight <- 1/( length( V(g) ) -1 )
# calculate the "weighted degree"
graph.strength(g)
[1] 1 1 1 1 1 1 1 1 1 1
Alternatively, perhaps you are looking for a normalized degree?
degree( g, normalized = TRUE )
[1] 1 1 1 1 1 1 1 1 1 1
source to share