CKres
February 15, 2022, 8:48pm
1
Using igraph:
I’m trying to create a sociogram of 30 individuals (top row) and how many censuses they were present (first column).
Majority of the observations in this dataset were present (indicated by a 1, an absence was indicated by a 0).
Essentially looks like this:
1 2 3
1 1 1 0
2 1 0 1
3 1 1 1
Any help would be great.
library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
indiv <- 1:10
set.seed(42)
basket <- sample(0:1,40, replace = TRUE)
census1 <-
census2 <- 1
census3 <- 1
census4 <- 1
object <- data.frame(indiv = indiv, census1 = census1, census2 = census2, census3 = census3, census4 = census4)
object[2:5] <- basket
object
#> indiv census1 census2 census3 census4
#> 1 1 0 0 0 1
#> 2 2 0 1 0 1
#> 3 3 0 0 0 1
#> 4 4 0 1 0 1
#> 5 5 1 0 0 0
#> 6 6 1 0 1 1
#> 7 7 1 1 0 0
#> 8 8 1 1 0 1
#> 9 9 0 1 0 1
#> 10 10 1 1 0 1
g <- graph.data.frame(d = object, directed = FALSE)
plot(g, vertex.label = V(g)$name)
1 Like
system
Closed
February 23, 2022, 1:39am
3
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.