Set Up
knitr::opts_chunk$set(echo = TRUE)
library(igraph);library(readr);library(dplyr);library(ggalt);library(flexdashboard)
## Warning: package 'igraph' was built under R version 3.4.4
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
## Warning: package 'dplyr' was built under R version 3.4.4
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:igraph':
##
## as_data_frame, groups, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Warning: package 'ggalt' was built under R version 3.4.4
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.4.4
## Warning: package 'flexdashboard' was built under R version 3.4.4
#Download Data
ClassData=read_csv("C:/Users/jcolu/OneDrive/Documents/Harrisburg/Fall 2018/ANLY 512/SocialNetworkSurvey_Fall2018 - Form Responses 1.csv")
## Parsed with column specification:
## cols(
## Timestamp = col_character(),
## `What is YOUR name?` = col_character(),
## `Student 1: Who have you worked with?` = col_character(),
## `Student 1: Number times you worked with this student this semester (enter a number)` = col_integer(),
## `Student 1: Is this student male or female?` = col_character(),
## `Student 1: Is this student in the same career/field as you?` = col_character(),
## `Student 2: Who else have you worked with?` = col_character(),
## `Student 2: Number times you worked with this student this semester (enter a number)` = col_integer(),
## `Student 2: Is this student male or female?` = col_character(),
## `Student 2: Is this student in the same career/field as you?` = col_character(),
## `Student 3: Who else have you worked with?` = col_character(),
## `Student 3: Number times you worked with this student this semester (enter a number)` = col_integer(),
## `Student 3: Is this student male or female?` = col_character(),
## `Student 3: Is this student in the same career/field as you?` = col_character()
## )
head(ClassData)
## # A tibble: 6 x 14
## Timestamp `What is YOUR na~ `Student 1: Who h~ `Student 1: Number time~
## <chr> <chr> <chr> <int>
## 1 11/24/201~ Jing Xie Yu Du 5
## 2 11/24/201~ Shixiong Li Mu Liu 5
## 3 11/24/201~ Shreyas Shekhar Jing Xie 3
## 4 11/24/201~ Ashish Bathija Vishant Girish Sh~ 6
## 5 11/25/201~ Ferinkumar Patel Vishant Girish Sh~ 1
## 6 11/25/201~ Yu Du Jing Xie 5
## # ... with 10 more variables: `Student 1: Is this student male or
## # female?` <chr>, `Student 1: Is this student in the same career/field
## # as you?` <chr>, `Student 2: Who else have you worked with?` <chr>,
## # `Student 2: Number times you worked with this student this semester
## # (enter a number)` <int>, `Student 2: Is this student male or
## # female?` <chr>, `Student 2: Is this student in the same career/field
## # as you?` <chr>, `Student 3: Who else have you worked with?` <chr>,
## # `Student 3: Number times you worked with this student this semester
## # (enter a number)` <int>, `Student 3: Is this student male or
## # female?` <chr>, `Student 3: Is this student in the same career/field
## # as you?` <chr>
Subset data
ClassData1=table(ClassData$`Student 1: Who have you worked with?`, ClassData$`Student 1: Is this student male or female?`)
ClassData2=table(ClassData$`Student 1: Who have you worked with?`, ClassData$`Student 1: Number times you worked with this student this semester (enter a number)`)
ClassData1
##
## Female Male
## Aruna Kumari Gadiraju 0 1
## Dmitry Kaleganov 0 1
## Enrique Cruz Avila 0 1
## Jing Xie 2 0
## Juan Antonio Colunga Pastrana 1 1
## Lan Shen 1 0
## Linyi Zhang 0 1
## Ming Xin 1 0
## Mu Liu 0 1
## Shijie Gong 0 1
## Shixiong Li 0 1
## Thai Nam Tran 0 1
## Vishant Girish Shah 0 2
## Wei Xu 0 1
## Xiaowei Yan 0 1
## Xichen Liu 1 0
## Yifei Yu 1 0
## Yu Du 1 0
ClassData2
##
## 0 1 2 3 4 5 6 10 15
## Aruna Kumari Gadiraju 0 1 0 0 0 0 0 0 0
## Dmitry Kaleganov 0 0 0 0 0 0 0 0 1
## Enrique Cruz Avila 0 0 1 0 0 0 0 0 0
## Jing Xie 0 0 0 1 0 1 0 0 0
## Juan Antonio Colunga Pastrana 0 0 0 0 0 2 0 0 0
## Lan Shen 0 1 0 0 0 0 0 0 0
## Linyi Zhang 1 0 0 0 0 0 0 0 0
## Ming Xin 0 0 0 0 0 0 1 0 0
## Mu Liu 0 0 0 0 0 1 0 0 0
## Shijie Gong 0 0 1 0 0 0 0 0 0
## Shixiong Li 0 0 0 0 0 0 0 1 0
## Thai Nam Tran 0 0 1 0 0 0 0 0 0
## Vishant Girish Shah 0 1 0 0 0 0 1 0 0
## Wei Xu 0 0 1 0 0 0 0 0 0
## Xiaowei Yan 0 0 0 0 1 0 0 0 0
## Xichen Liu 0 0 0 0 1 0 0 0 0
## Yifei Yu 0 0 0 0 0 1 0 0 0
## Yu Du 0 0 0 0 0 1 0 0 0
Create the igraph object
G1=graph_from_data_frame(ClassData1)
G2=graph_from_data_frame(ClassData2)
G1
## IGRAPH 683971f DN-- 20 36 --
## + attr: name (v/c), Freq (e/n)
## + edges from 683971f (vertex names):
## [1] Aruna Kumari Gadiraju ->Female
## [2] Dmitry Kaleganov ->Female
## [3] Enrique Cruz Avila ->Female
## [4] Jing Xie ->Female
## [5] Juan Antonio Colunga Pastrana->Female
## [6] Lan Shen ->Female
## [7] Linyi Zhang ->Female
## [8] Ming Xin ->Female
## + ... omitted several edges
G2
## IGRAPH 6841f8d DN-- 27 162 --
## + attr: name (v/c), Freq (e/n)
## + edges from 6841f8d (vertex names):
## [1] Aruna Kumari Gadiraju ->0 Dmitry Kaleganov ->0
## [3] Enrique Cruz Avila ->0 Jing Xie ->0
## [5] Juan Antonio Colunga Pastrana->0 Lan Shen ->0
## [7] Linyi Zhang ->0 Ming Xin ->0
## [9] Mu Liu ->0 Shijie Gong ->0
## [11] Shixiong Li ->0 Thai Nam Tran ->0
## [13] Vishant Girish Shah ->0 Wei Xu ->0
## [15] Xiaowei Yan ->0 Xichen Liu ->0
## + ... omitted several edges
Plot relationships
Graph 1
plot(G1)

Graph 2
plot(G2)
