Watts-College / crj-507-spring-2024

https://watts-college.github.io/crj-507-spring-2024/
MIT License
1 stars 0 forks source link

Final Lab - PhxArrestNet2023 Not Found? #27

Closed Drake14 closed 6 months ago

Drake14 commented 6 months ago

Hello! I am trying to plot out the PhxArrestNet2023 network, but I have run into two different errors that I am having trouble solving. It will either say that object 'PhxArrestNet2023' is not found, or RStudio does not recognize gplot() as a function. I have made sure that the SNA and network libraries are loaded in and double checked my variable names.

Here is my current code:

##### 1. Creating an object of class matrix from PhxArrestNet2023 #####
matrixPhxArrest2023 <- as.matrix( PhxArrestNet2023 )

##### 2. Plot the Phoenix Arrest 2023 Bipartite Network #####
gplot(
  PhxArrestNet2023,                                                                 # Network to plot 
  gmode = "twomode",                                                            # Two mode indication
  usearrows = FALSE,                                                                # Directionality
  vertex.cex=2,                                                                          # Node Size     
  label.cex=1.2,                                                                          # Label Size
  vertex.col = c(                                                                         # Vector of colors
         rep( "#fa6e7a", dim( matrixPhxArrest2023 )[1] ),             # Person color distinction
         rep( "#00aaff", dim( matrixPhxArrest2023 )[2] ) ),            # Group color distinction
  main="Bipartite Graph of 2023 Phoenix Arrest Network"      # Title
)
jacobtnyoung commented 6 months ago

Hi @Drake14 ! Can you print out the object 'PhxArrestNet2023'? Just enter the object name and make sure it returns it.

jacobtnyoung commented 6 months ago

Hi @Drake14! Run this block of code and see if the plot works:


# set the url
loc <- "https://github.com/jacobtnyoung/sna-textbook/raw/main/data/data-PHX-arrest-2023-net.rds"

# for the 2023
PhxArrestNet2023 <- readRDS( url( loc ) )

library( sna )

gplot(
  PhxArrestNet2023,
  gmode = "twomode"

)

If this works for you, then you might have a command that is removing the object somewhere.

Drake14 commented 6 months ago

Hi! I just attempted to print out the 2023 network and tried that code block as well.

When trying to print an output PhxArrestNet2023, I do not get an error code, but it does not display any results. I also set echo = TRUE to debug just in case, but there is no output after calling for PhxArrestNet2023.

After trying the code block, this is the new error I am getting: Error: ! object 'PhxArrestNet2023' not found Backtrace:

  1. sna::gplot(PhxArrestNet2023, gmode = "twomode")
  2. sna::as.edgelist.sna(dat, force.bipartite = (gmode == "twomode"))
jacobtnyoung commented 6 months ago

Hi @Drake14! Try running it directly in RStudio, not from the .Rmd file. I would close RStudio, reopen it, and then copy and paste this piece directly into the command line.

Drake14 commented 6 months ago

After trying to run the code directly in the command line, it appears to be printing the network characteristics: Network attributes: vertices = 2432 directed = TRUE hyper = FALSE loops = FALSE multiple = FALSE bipartite = 1698 total edges= 2678 missing edges= 0 non-missing edges= 2678

I have still yet figured out how or why I am getting the error code within the .Rmd file unfortunately.

Drake14 commented 6 months ago

Hi @jacobtnyoung! Just as a quick update, I was able to figure it out! I had a feeling that for some reason, when calling for PhxArrestNet2023, that variable must have been out of scope since R could not identify it. Within the R Markdown, I noticed that eval was set to FALSE, which will not allow the compiler to evaluate the code that read in the networks. I would imagine others will run into a similar issue once they begin, but it is an easy fix once I found it! :)

Edit: This is also why R could not identify the gplot() function as this is the same section of code where we load in our libraries.

jacobtnyoung commented 6 months ago

Hi @Drake14! Glad you figured it out! 🤙🏼