Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion Assignment 3.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Since our data represnts every time a student makes a comment there are multiple

EDGE <- count(D2, comment.to, comment.from)

names(EDGE) <- c("from", "to", "count")
names(EDGE) <- c("to", "from", "count")

```

Expand Down Expand Up @@ -105,6 +105,18 @@ In Part II your task is to [look up](http://igraph.org/r/) in the igraph documen
* Ensure that sizing allows for an unobstructed view of the network features (For example, the arrow size is smaller)
* The vertices are colored according to major
* The vertices are sized according to the number of comments they have recieved
```{r}

plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$major, edge.width=EDGE$count)

commentnumb <- count(D1, comment.to)
names(commentnumb) <- c("id","count")
commentnumb <- left_join(VERTEX,commentnumb,by=c("id"))
commentnumb$count[is.na(commentnumb$count)] <- 0

plot(g,layout=layout.fruchterman.reingold, vertex.color=VERTEX$major, edge.width=EDGE$count, edge.arrow.size= 0.5, vertex.size=15+commentnumb$count)

```

## Part III

Expand All @@ -121,3 +133,58 @@ Once you have done this, also [look up](http://igraph.org/r/) how to generate th
### To Submit Your Assignment

Please submit your assignment by first "knitting" your RMarkdown document into an html file and then comit, push and pull request both the RMarkdown file and the html file.

```{r}
library(tidyr)
library(dplyr)
library(stringr)
library(igraph)
C1 <- read.csv("hudk4050-classes.csv", stringsAsFactors = FALSE, header = TRUE)
C2 <- C1
```
# Data Tidying
```{r}
colnames(C2) <- C2[1,]
C2 <- slice(C2,3:49)
C2 <- select(C2,1:8)
C2 <- unite(C2, "name", `First Name`, `Last Name`, sep = " ")
C2$name <- str_replace(C2$name,"`","")
C2$name <- str_to_title(C2$name)
C2 <- C2 %>% mutate_at(2:7, list(toupper))
C2 <- C2 %>% mutate_at(2:7, str_replace_all, " ", "")

```
#Data Restructring
```{r}
C3 <- C2 %>% gather(label,class, 2:7, na.rm = TRUE, convert = FALSE) %>% select(name, class)
C3$count <- 1
C3 <- filter(C3, class != "")
C3 <- unique(C3)
C3 <- spread(C3, class, count)
rownames(C3) <- C3$name
C3 <- select(C3, -name, -HUDK4050)
C3[is.na(C3)] <- 0
```
# Matrix Operations
```{r}
C4 <- as.matrix(C3)
C4 <- C4 %*% t(C4)
```
# Graphing
```{r}
g <- graph.adjacency(C4, mode="undirected", diag = FALSE)
plot(g,layout=layout.fruchterman.reingold, vertex.size = 4,
#degree(g)*0.7,
vertex.label.cex=0.8,
vertex.label.color="black",
vertex.color="blue")
```

#Centrality
```{r}
sort(degree(g), decreasing = TRUE)
sort(betweenness(g), decreasing = TRUE)
```

Based on the data we can find that Yifei Zhang is the most central person in the network, and he/she connects two centralized groups. Therefore, she is the most appropriate person to help students contacting each other.

Loading