Network plotting with igraph in R - differntiating vertices and edges -



Network plotting with igraph in R - differntiating vertices and edges -

i'm struggling social network mapping r using igraph. produce plot showing relationships of local representative (e.g. bill) individuals , administrative bodies in area. i've been able plot vertices bill , contacts edges using next in graph.data.frame:

who contact weight associate bill district 1 y bill part 2 n bill small town 1 y bill small town b 2 n bill social worker 1 n bill steve 1 y bill church 2 n bill jane 1 y bill small town admin 1 n bill small town b admin 1 n

i differentiate vertices color whether or not 1 of bill's associates. tried

v(g)$color <- ifelse(v(g)

but either error message or nil changes. differentiate edges in different colors weight represent between bill's direct or indirect contacts using weight variable.

any guidance on how can enhance bill's plot or whether should using different dataframe appreciated.

the reason why "associate" code isn't working when graph.data.frame attributes stored edges supply, not vertices. here's how can add together vertex info (and plot weights using @jlhoward's suggestion)

#sample info dd <- structure(list(who = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l), .label = "bill", class = "factor"), contact = c("district", "region", "villagea", "villageb", "socialworker", "steve", "church", "jane", "villageaadmin", "villagebadmin"), weight = c(1l, 2l, 1l, 2l, 1l, 1l, 2l, 1l, 1l, 1l), associate = c("y", "n", "y", "n", "n", "y", "n", "y", "n", "n")), .names = c("who", "contact", "weight", "associate"), row.names = c(na, -10l), class = "data.frame")

and code

library(igraph) gg <- graph.data.frame(dd[,1:3]) v(gg)[dd$contact]$associate <- dd$associate v(gg)$color <- ifelse(v(gg)$associate=="y", "green","orange") plot(gg,edge.color=e(gg)$weight)

which produces

r igraph

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -