0

I've been working on this a while to no avail. I'm using both statnet to create some networks in r from survey data. The way the networks are measured in the survey allowed respondents to list network contacts not included in the survey. The way it turned out is that many network responses were surveyed, just a few are not. I'm trying to map colors to nodes based on other survey responses.

This is a replication of my issue. I want to label the nodes that have available attributes with their attribute and label those without as 'unknown' or NA or ''.

install.packages('statnet')
library(statnet)


mydata <- data.frame(
  src=c('bob','sue','tom','john','sheena'),
  trg=c('tom','billy','billy','bob','chris'),
  vary_1=c(1,2,2,3,1)

)

net_1 <- network(mydata[1:2])


##### My attempt using dplyr to create labels ####
# it doesn't work

labs <-  mydata %>% 
  mutate(flag = .[,1] %in% .[,2]) %>% 
  gather(key,value,-flag,-vary_1) %>% 
  mutate(i=ifelse(.$key=='trg',.$vary_1==NA,.$vary_1)) %>% 
  select(value) %>% 
  unique() %>% 
  .[,1] #### I think this approach is something close

set.seed(123)
gplot(net_1,vertex.cex = degree(net_1),
      label=labs)  #labels using the labs created above
elliot
  • 1,844
  • 16
  • 45
  • Can you post your desired output? Your code errors on my machine. – Psidom Oct 06 '17 at 23:04
  • Hi my desired output is a network graph that has the vary_y1 column as the node labels. I will post a graph picture as soon as I'm able (its late here). Thanks. – elliot Oct 06 '17 at 23:22

0 Answers0