library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.3
library(scales)
## Warning: package 'scales' was built under R version 4.4.3
library(tidygraph)
## Warning: package 'tidygraph' was built under R version 4.4.3
##
## Attaching package: 'tidygraph'
## The following object is masked from 'package:stats':
##
## filter
library(ggraph)
## Warning: package 'ggraph' was built under R version 4.4.3
library(purrr)
## Warning: package 'purrr' was built under R version 4.4.3
##
## Attaching package: 'purrr'
## The following object is masked from 'package:scales':
##
## discard
# Read the Excel dataset
email.edges <- read_excel("EmployeeEmails.xlsx", sheet = "Emails")
email.nodes <- read_excel("EmployeeEmails.xlsx", sheet = "Departments")
email <- tbl_graph(nodes = email.nodes, edges = email.edges, directed = TRUE)
email
## # A tbl_graph: 30 nodes and 149 edges
## #
## # A directed simple graph with 1 component
## #
## # Node Data: 30 × 2 (active)
## employee department
## <dbl> <chr>
## 1 1 Marketing
## 2 2 HR
## 3 3 Operations
## 4 4 Marketing
## 5 5 Marketing
## 6 6 HR
## 7 7 HR
## 8 8 HR
## 9 9 Purchase
## 10 10 Purchase
## # ℹ 20 more rows
## #
## # Edge Data: 149 × 3
## from to frequency
## <int> <int> <dbl>
## 1 1 2 1
## 2 1 6 13
## 3 1 7 22
## # ℹ 146 more rows
With the network data provided (i.e., the email datasets), create three different network graphs to visualize the email communications between employees across departments. Please note the following requirements: (1) At least one of the three visualizations should show the nodes and edges, and (2) At least one of the three visualizations should show the frequency of emails in addition to the nodes and edges (failing to meet the requirements will lead to a 20-point deduction per requirement). Submit the data, the visualizations, a short write-up of what you needed to do to create the visualization, and a description of each visualization. Follow the proper design techniques (e.g., show/hide the legend, effective use of color, filter to the leaf nodes, etc.) that we have gone over in class ##### Graph 1
ggraph(email, layout = "fr") +
geom_edge_link(aes(width=frequency),alpha = 0.3,
color="black",
arrow = arrow(length=unit(1,"mm"), type = "open"),
end_cap = circle(2,"mm"),
angle_calc = "along",
label_colour = "white",
label_dodge = unit(5, "mm")) +
scale_edge_width(range = c(1.9, 1))+
geom_node_point(aes(color = department), size = 6)+
theme_void() +
labs(title = "Email Network by Department")+
theme(plot.title = element_text(hjust = 0.5, color = "black", size = 18))+
geom_node_text(aes(label = employee), size = 3, color = "black", nudge_y = 0)
##### Graph 2
#Question 1 Graph 2
ggraph(email, layout = 'stress') +
geom_edge_parallel(alpha = 0.54, color = "#333333", arrow = arrow(length=unit(2,"mm"),type="closed"), end_cap=circle(1.5,"mm"))+
theme(legend.position = "bottom")+
ggtitle("Weighted Email Communication Network") +
theme(plot.title = element_text(hjust = 0.5, color = "red", size = 18))+
geom_node_point(aes(color=factor(department), size = .25))+
geom_node_text(aes(label = employee), size = 3, color = "white", nudge_y = 0)
#Question 1 Graph 3
ggraph(email, layout = 'linear' , circular = TRUE) +
geom_edge_arc(alpha = .9) +
ggtitle("Circular layout grouped by department") +
theme(plot.title = element_text(hjust = 0.7, color = "green", size = 16))+
geom_node_point(aes(color = department)) +
coord_fixed()
#Question 1 Graph 4
ggraph(email, layout = 'linear') +
geom_edge_arc(alpha = .3,color="red") +
ggtitle("Email Network") +
theme(plot.title = element_text(hjust = 0.5, color = "pink", size = 18))+
geom_node_point(aes(color = department), alpha=1)
With the hierarchical data provided (i.e., the dataset of Magnoliopsida plants in Colorado), create three different graphs to visualize the “Class-Order-Family-Genus” hierarchy. Please do not include details at the level of Scientific Name in the visualizations (failing to do so may compromise the quality of the visualizations due to the large number of leaf nodes). Submit the data, the visualizations, a short write-up of what you needed to do to create the visualization, and a description of each visualization. Follow the proper design techniques (e.g., show/hide the legend, effective use of color, filter to the leaf nodes, etc.) that we have gone over in class.
plants.raw <- read.csv("C:/Users/C837365439/OneDrive - Colostate/CIS576/Assignment4/COPlants_Magnoliopsida.csv")
plants.taxonomy <- read.csv("C:/Users/C837365439/OneDrive - Colostate/CIS576/Assignment4/COPlants_Magnoliopsida.csv") %>%
select(Class, Order, Family, Genus) %>%
distinct()
plants.edges <- map_df(7:9, ~select(plants.raw,all_of((.x-1):.x)) %>%
setNames(c("from", "to")) %>%
distinct()
)
plants.graph <- as_tbl_graph(plants.edges) %>%
activate(nodes) %>%
left_join(plants.taxonomy, by = c("name" = "Genus"))
plants.graph
## # A tbl_graph: 477 nodes and 476 edges
## #
## # A rooted tree
## #
## # Node Data: 477 × 4 (active)
## name Class Order Family
## <chr> <chr> <chr> <chr>
## 1 Magnoliopsida <NA> <NA> <NA>
## 2 Sapindales <NA> <NA> <NA>
## 3 Caryophyllales <NA> <NA> <NA>
## 4 Apiales <NA> <NA> <NA>
## 5 Gentianales <NA> <NA> <NA>
## 6 Asterales <NA> <NA> <NA>
## 7 Ranunculales <NA> <NA> <NA>
## 8 Lamiales <NA> <NA> <NA>
## 9 Capparales <NA> <NA> <NA>
## 10 Campanulales <NA> <NA> <NA>
## # ℹ 467 more rows
## #
## # Edge Data: 476 × 2
## from to
## <int> <int>
## 1 1 2
## 2 1 3
## 3 1 4
## # ℹ 473 more rows
#Question 2 Graph 1
ggraph(plants.graph, "circlepack") +
geom_edge_diagonal(alpha = 0.3, color = "gray50") +
geom_node_point(alpha = 0.9, aes(color = Order, filter = leaf), size = 3) +
geom_node_text(aes(filter = (depth == 2), label = name),
check_overlap = TRUE, color = "brown", alpha = 0.9, size = 2) +
geom_node_text(aes(filter = (depth == 1), label = name),
check_overlap = TRUE, color = "black", alpha = 0.9, size = 4, fontface = "bold") +
theme_void() +
theme(legend.position = "bottom",
plot.title = element_text(hjust = 0.5, size = 16, face = "bold")) +
labs(title = "Colorado Plants", color = "Order") +
theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))
#Question 2 Graph 2
ggraph(plants.graph, "circlepack") +
geom_edge_diagonal(alpha = 0.1, color = "gray50") +
geom_node_point(alpha = 0.8, aes(color = Order, filter = leaf), size = 2) +
geom_node_text(aes(filter = (depth == 2), label = name), check_overlap = TRUE, color = "brown", alpha = 0.9, size = 4) +
geom_node_text(aes(filter = (depth == 1), label = name), check_overlap = TRUE, color = "black", alpha = 0.9, fontface = "bold", size = 6) +
theme_void() +
theme(legend.position = "right +",plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))
ggtitle("Colorado plants") +
scale_color_brewer(palette = "Set1", name = "Order")
## NULL
#Question 2 Graph 3
ggraph(plants.graph, layout = 'partition') +
geom_node_tile(aes(fill = depth), size=.4) +
ggtitle("Colorado plants")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
##### Graph 4
#Question 2 Graph 4
ggraph(plants.graph, layout = 'partition', circular=TRUE) +
geom_node_arc_bar(aes(fill = depth), size=.5) +
coord_fixed() +
ggtitle("Colorado plants")
##### Graph 5
#Question 2 Graph 5
ggraph(plants.graph, layout = 'dendrogram', circular=TRUE) +
geom_edge_diagonal() +
geom_node_point(aes(filter = leaf, color = Order, fill = Order), size = 4, shape = 25) +
coord_fixed() +
ggtitle("Colorado Plants")
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(dplyr)
library(readxl)
library(tidyr)
library(scales)
library(tidygraph)
library(ggraph)
library(purrr)
# Read the Excel dataset
email.edges <- read_excel("EmployeeEmails.xlsx", sheet = "Emails")
email.nodes <- read_excel("EmployeeEmails.xlsx", sheet = "Departments")
email <- tbl_graph(nodes = email.nodes, edges = email.edges, directed = TRUE)
email
ggraph(email, layout = "fr") +
geom_edge_link(aes(width=frequency),alpha = 0.3,
color="black",
arrow = arrow(length=unit(1,"mm"), type = "open"),
end_cap = circle(2,"mm"),
angle_calc = "along",
label_colour = "white",
label_dodge = unit(5, "mm")) +
scale_edge_width(range = c(1.9, 1))+
geom_node_point(aes(color = department), size = 6)+
theme_void() +
labs(title = "Email Network by Department")+
theme(plot.title = element_text(hjust = 0.5, color = "black", size = 18))+
geom_node_text(aes(label = employee), size = 3, color = "black", nudge_y = 0)
#Question 1 Graph 2
ggraph(email, layout = 'stress') +
geom_edge_parallel(alpha = 0.54, color = "#333333", arrow = arrow(length=unit(2,"mm"),type="closed"), end_cap=circle(1.5,"mm"))+
theme(legend.position = "bottom")+
ggtitle("Weighted Email Communication Network") +
theme(plot.title = element_text(hjust = 0.5, color = "red", size = 18))+
geom_node_point(aes(color=factor(department), size = .25))+
geom_node_text(aes(label = employee), size = 3, color = "white", nudge_y = 0)
#Question 1 Graph 3
ggraph(email, layout = 'linear' , circular = TRUE) +
geom_edge_arc(alpha = .9) +
ggtitle("Circular layout grouped by department") +
theme(plot.title = element_text(hjust = 0.7, color = "green", size = 16))+
geom_node_point(aes(color = department)) +
coord_fixed()
#Question 1 Graph 4
ggraph(email, layout = 'linear') +
geom_edge_arc(alpha = .3,color="red") +
ggtitle("Email Network") +
theme(plot.title = element_text(hjust = 0.5, color = "pink", size = 18))+
geom_node_point(aes(color = department), alpha=1)
plants.raw <- read.csv("C:/Users/C837365439/OneDrive - Colostate/CIS576/Assignment4/COPlants_Magnoliopsida.csv")
plants.taxonomy <- read.csv("C:/Users/C837365439/OneDrive - Colostate/CIS576/Assignment4/COPlants_Magnoliopsida.csv") %>%
select(Class, Order, Family, Genus) %>%
distinct()
plants.edges <- map_df(7:9, ~select(plants.raw,all_of((.x-1):.x)) %>%
setNames(c("from", "to")) %>%
distinct()
)
plants.graph <- as_tbl_graph(plants.edges) %>%
activate(nodes) %>%
left_join(plants.taxonomy, by = c("name" = "Genus"))
plants.graph
#Question 2 Graph 1
ggraph(plants.graph, "circlepack") +
geom_edge_diagonal(alpha = 0.3, color = "gray50") +
geom_node_point(alpha = 0.9, aes(color = Order, filter = leaf), size = 3) +
geom_node_text(aes(filter = (depth == 2), label = name),
check_overlap = TRUE, color = "brown", alpha = 0.9, size = 2) +
geom_node_text(aes(filter = (depth == 1), label = name),
check_overlap = TRUE, color = "black", alpha = 0.9, size = 4, fontface = "bold") +
theme_void() +
theme(legend.position = "bottom",
plot.title = element_text(hjust = 0.5, size = 16, face = "bold")) +
labs(title = "Colorado Plants", color = "Order") +
theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))
#Question 2 Graph 2
ggraph(plants.graph, "circlepack") +
geom_edge_diagonal(alpha = 0.1, color = "gray50") +
geom_node_point(alpha = 0.8, aes(color = Order, filter = leaf), size = 2) +
geom_node_text(aes(filter = (depth == 2), label = name), check_overlap = TRUE, color = "brown", alpha = 0.9, size = 4) +
geom_node_text(aes(filter = (depth == 1), label = name), check_overlap = TRUE, color = "black", alpha = 0.9, fontface = "bold", size = 6) +
theme_void() +
theme(legend.position = "right +",plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))
ggtitle("Colorado plants") +
scale_color_brewer(palette = "Set1", name = "Order")
#Question 2 Graph 3
ggraph(plants.graph, layout = 'partition') +
geom_node_tile(aes(fill = depth), size=.4) +
ggtitle("Colorado plants")
#Question 2 Graph 4
ggraph(plants.graph, layout = 'partition', circular=TRUE) +
geom_node_arc_bar(aes(fill = depth), size=.5) +
coord_fixed() +
ggtitle("Colorado plants")
#Question 2 Graph 5
ggraph(plants.graph, layout = 'dendrogram', circular=TRUE) +
geom_edge_diagonal() +
geom_node_point(aes(filter = leaf, color = Order, fill = Order), size = 4, shape = 25) +
coord_fixed() +
ggtitle("Colorado Plants")
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(dplyr)
library(readxl)
library(tidyr)
library(scales)
library(tidygraph)
library(ggraph)
email.edges <- read_excel("EmployeeEmails.xlsx", sheet = "Emails")
email.nodes <- read_excel("EmployeeEmails.xlsx", sheet = "Departments")
email <- tbl_graph(nodes = email.nodes, edges = email.edges, directed = TRUE)
email
library(igraph)
library(ggraph)
ggraph(email, layout = "fr") +
geom_edge_link(aes(width=frequency),alpha = 0.3,
color="black",
arrow = arrow(length=unit(1,"mm"), type = "open"),
end_cap = circle(2,"mm"),
angle_calc = "along",
label_colour = "white",
label_dodge = unit(5, "mm")) +
scale_edge_width(range = c(1.9, 1))+
geom_node_point(aes(color = department), size = 6)+
theme_void() +
labs(title = "Email Network by Department")+
theme(plot.title = element_text(hjust = 0.5, color = "black", size = 18))+
geom_node_text(aes(label = employee), size = 3, color = "black", nudge_y = 0)
ggraph(email, layout = 'stress') +
geom_edge_parallel(alpha = 0.54, color = "#333333", arrow = arrow(length=unit(2,"mm"),type="closed"), end_cap=circle(1.5,"mm"))+
theme(legend.position = "bottom")+
ggtitle("Weighted Email Communication Network") +
theme(plot.title = element_text(hjust = 0.5, color = "red", size = 18))+
geom_node_point(aes(color=factor(department), size = .25))+
geom_node_text(aes(label = employee), size = 3, color = "white", nudge_y = 0)
ggraph(email, layout = 'linear' , circular = TRUE) +
geom_edge_arc(alpha = .9) +
ggtitle("Circular layout grouped by department") +
theme(plot.title = element_text(hjust = 0.7, color = "green", size = 16))+
geom_node_point(aes(color = department)) +
coord_fixed()
ggraph(email, layout = 'linear') +
geom_edge_arc(alpha = .3,color="red") +
ggtitle("Email Communication Network") +
theme(plot.title = element_text(hjust = 0.5, color = "pink", size = 18))+
geom_node_point(aes(color = department), alpha=1)
plants.raw <- read.csv("C:/Users/C837365439/OneDrive - Colostate/CIS576/Assignment4/COPlants_Magnoliopsida.csv")
plants.taxonomy <- read.csv("C:/Users/C837365439/OneDrive - Colostate/CIS576/Assignment4/COPlants_Magnoliopsida.csv") %>%
select(Class, Order, Family, Genus) %>%
distinct()
plants.edges <- map_df(7:9, ~select(plants.raw,all_of((.x-1):.x)) %>%
setNames(c("from", "to")) %>%
distinct()
)
plants.graph <- as_tbl_graph(plants.edges) %>%
activate(nodes) %>%
left_join(plants.taxonomy, by = c("name" = "Genus"))
plants.graph
ggraph(plants.graph, "circlepack") +
geom_edge_diagonal(alpha = 0.3, color = "gray50") +
geom_node_point(alpha = 0.9, aes(color = Order, filter = leaf), size = 3) +
geom_node_text(aes(filter = (depth == 2), label = name),
check_overlap = TRUE, color = "brown", alpha = 0.9, size = 2) +
geom_node_text(aes(filter = (depth == 1), label = name),
check_overlap = TRUE, color = "black", alpha = 0.9, size = 4, fontface = "bold") +
theme_void() +
theme(legend.position = "bottom",
plot.title = element_text(hjust = 0.5, size = 16, face = "bold")) +
labs(title = "Colorado Plants", color = "Order") +
theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))
ggraph(plants.graph, "circlepack") +
geom_edge_diagonal(alpha = 0.1, color = "gray50") +
geom_node_point(alpha = 0.8, aes(color = Order, filter = leaf), size = 2) +
geom_node_text(aes(filter = (depth == 2), label = name), check_overlap = TRUE, color = "brown", alpha = 0.9, size = 4) +
geom_node_text(aes(filter = (depth == 1), label = name), check_overlap = TRUE, color = "black", alpha = 0.9, fontface = "bold", size = 6) +
theme_void() +
theme(legend.position = "right +",plot.title = element_text(hjust = 0.5, size = 16, face = "bold"))
ggtitle("Colorado plants") +
scale_color_brewer(palette = "Set1", name = "Order")
ggraph(plants.graph, layout = 'partition') +
geom_node_tile(aes(fill = depth), size=.4) +
ggtitle("Colorado plants")
ggraph(plants.graph, layout = 'partition', circular=TRUE) +
geom_node_arc_bar(aes(fill = depth), size=.5) +
coord_fixed() +
ggtitle("Colorado plants")
ggraph(plants.graph, layout = 'dendrogram', circular=TRUE) +
geom_edge_diagonal() +
geom_node_point(aes(filter = leaf, color = Order, fill = Order), size = 4, shape = 25) +
coord_fixed() +
ggtitle("Colorado Plants")