challenge_1
instructions
Loading Data and Creating a Network
Author

Rahul Gundeti

Published

February 13, 2023

Challenge Overview

This Challenge is to

1) Read a dataset, and

2) Create a network object

Loading the data

Read in one (or more) of the following data sets, using the correct R package and command.

- got_marriages.csv

- fish_encounters dataset (available in the `tidyr` package)

- got_like_dislike.csv

Code
library(readr)
Warning: package 'readr' was built under R version 4.1.3
Code
got_like_dislike <- read_csv("_data/got/got_like_dislike.csv")
Rows: 46 Columns: 49
-- Column specification --------------------------------------------------------
Delimiter: ","
chr  (3): Current house, Former house, Name
dbl (46): Lysa Arryn, Petyr Baelish, Joffrey Baratheon, Margaery Tyrell, Ren...

i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
head(got_like_dislike)
# A tibble: 6 x 49
  `Current house` `Former house` Name              `Lysa Arryn` `Petyr Baelish`
  <chr>           <chr>          <chr>                    <dbl>           <dbl>
1 Arryn           Tully          Lysa Arryn                  NA               3
2 Baelish         <NA>           Petyr Baelish                3              NA
3 Lannister       Baratheon      Joffrey Baratheon            0              -1
4 Tyrell          Baratheon      Margaery Tyrell              0               1
5 Baratheon       <NA>           Renly Baratheon              0              -2
6 Baratheon       <NA>           Robert Baratheon             2               1
# i 44 more variables: `Joffrey Baratheon` <dbl>, `Margaery Tyrell` <dbl>,
#   `Renly Baratheon` <dbl>, `Robert Baratheon` <dbl>,
#   `Stannis Baratheon` <dbl>, `Brienne of Tarth` <dbl>, Bronn <dbl>,
#   `Gregor Clegane` <dbl>, `Sandor Clegane` <dbl>, `Xaro Xhoan Daxos` <dbl>,
#   Gendry <dbl>, `Balon Greyjoy` <dbl>, `Theon Greyjoy` <dbl>,
#   `Jaqen H'ghar` <dbl>, Hodor <dbl>, `Khal Drogo` <dbl>,
#   `Cersei Lannister` <dbl>, `Jaime Lannister` <dbl>, ...

Creating a network

Load the package `igraph` and create an `igraph` object (i.e. a graph or network) in the form of an edge list. The command may vary whether the data is given as a list of connections or an adjacency matrix. Is the network directed or undirected; weighted or unweighted; unimodal or bipartite? Can you plot it?

Code
library(igraph)
Warning: package 'igraph' was built under R version 4.1.3

Attaching package: 'igraph'
The following objects are masked from 'package:stats':

    decompose, spectrum
The following object is masked from 'package:base':

    union
Code
net.igraph <- graph_from_data_frame(got_like_dislike, directed = TRUE)
Warning in graph_from_data_frame(got_like_dislike, directed = TRUE): In `d' `NA'
elements were replaced with string "NA"
Code
# Check if the network is directed or undirected, weighted or unweighted, unimodal or bipartite
is_bipartite(net.igraph)
[1] FALSE
Code
is_weighted(net.igraph) 
[1] FALSE
Code
is_directed(net.igraph) 
[1] TRUE
Code
plot(net.igraph)