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