0

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)

eli
  • 184
  • 2
  • 12

1 Answers1

1

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)

enter image description here

Chris
  • 320
  • 2
  • 10
  • thank you , if I want to have 2 political parties lets say instead of just "PS", I want also "UDF", both together ,do you know how can I do this? g=subgraph.edges(graph=fblog, eids=which(V(fblog)$PolParty==" PS"& V(fblog)$PolParty==" UDF"), delete.vertices = TRUE) – eli May 24 '20 at 19:52
  • SORRY YOU KNOW HOW TO DO THIS? – eli May 24 '20 at 20:32
  • 1
    Updated with a boolean term to say `equal to 'PS' OR 'UDF'` – Chris May 24 '20 at 20:57
  • can you help me to modify the code ? I use table(V(g)$PolParty) , it gives me again all node also with other attribute, can you help me to modify the code ? because I just want NODES WHICH PolParty==" PS" and PolParty==" Les Verts".I dont know why – eli May 25 '20 at 18:56
  • 1
    I GOT IT, THIS IS CORRECT: new_graph<-induced.subgraph(fblog,which(V(fblog)$PolParty %in% c(" PS"," UDF"))) new_graph table(V(new_graph)$PolParty) – eli May 25 '20 at 19:36