Reputation: 184
I have a fblog data set ,PolParty is one attribute of my data, I want to plot just 2 political parties (say P1 and P2) and plot the network of blogs. i wrote code below but i think it is wrong , can some one help me?
library(statnet)
library(igraph)
library(sand)
data(fblog)
fblog = upgrade_graph(fblog)
class(fblog)
summary(fblog)
V(fblog)$PolParty
table(V(fblog)$PolParty)
p1<-V(fblog)[PolParty=="PS"] # by their labels/names
p2<-V(fblog)[PolParty=="UDF"]
class(p1)
Upvotes: 0
Views: 635
Reputation: 310
The objects p1
and p2
that you were creating are of the class igraph.vs
(instead of igraph
). This object just documents the vertices. Which is not a full graph. Hence when you try to plot it you don't get anything.
Based on the following post: Subset igraph graph by label
g=subgraph.edges(graph=fblog, eids=which(V(fblog)$PolParty==" PS"), delete.vertices = TRUE)
plot(g)
The above works. NOTE: regarding the output of V(fblog)$PolParty
- everything is preceeded by a space hence you need to use V(fblog)$PolParty==" PS"
UPDATE: if I want to subset based on 2 conditions- I will modify the which()
command:
g=subgraph.edges(graph=fblog, eids=which(V(fblog)$PolParty==" PS"| V(fblog)$PolParty==" UDF"), delete.vertices = TRUE)
plot(g)
Upvotes: 1