Closed jjgillis0 closed 5 months ago
Hi @jjgillis0 ! Take a look at your first line:
dim( PaulRevereNet )[1]
That should be:
dim( as.matrix( PaulRevereNet ) )[1]
Try that and work through your code. Also, your last line doesn't make sense. You are assigning the equation for the density to the PaulRevereNet
network object.
Thank you! I fixed everything and accidentally took the 'density' out in the last few lines.
Hi @jjgillis0 , great!
Hello Professor Young~
Working through Part 2 of the lab, I am getting a numeric (0) or non-numberic to binary for the density. When identifying the actors and events (M, N) I tried to do the same for L, edges, but that wasn't working either.
Here is my code:
N <- dim( PaulRevereNet )[1]
PaulRevereNet <- as.network( PaulRevereNet, # here is our matrix PaulRevereNet = N # define the number of actors ) PaulRevereNet
identify the number of events in the example
M <- dim( PaulRevereNet )[2] PaulRevereNet <- as.network( PaulRevereNet, # here is our matrix PaulRevereNet = M # define the number of actors )
actor.col <- rep( "#2067bf")
event.col <- rep( "#fef65b")
now combine them into a single vector of colors
node.col <- c( actor.col, event.col )
take a look
node.col
set the seed to reproduce the plot layout
set.seed( 507 )
execute the plot
gplot( PaulRevereNet, # our network to plot label = network.vertex.names( PaulRevereNet ), # the labels we want gmode = "twomode", # indicate it is two modes usearrows = FALSE, # turn off the arrowheads vertex.cex=2, # size the nodes
label.cex=1.2, # size the labels main="Paul Revere's Ride", # add a title
here is the addition to what we had above:
vertex.col = node.col # add the colors )
L <- sum(PaulRevereNet )
PaulRevereNet <- as.network( PaulRevereNet, PaulRevereNet = L
)
calculate the density
PaulRevereNet<- L / ( N * M )
check it out
PaulRevereNet