library(ggnetwork)
## Loading required package: ggplot2
library(network)
##
## 'network' 1.18.1 (2023-01-24), part of the Statnet Project
## * 'news(package="network")' for changes since last version
## * 'citation("network")' for citation information
## * 'https://statnet.org' for help, support, and other information
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggrepel)
library(readr)
library(ggplot2)
artists <- read_csv("Desktop/RWorkingDirectory/Working Directory/artists_2012_2020.csv")
## Rows: 284 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Artist
## dbl (4): Gender, GrammyWinner, GrammyNomminee, YearStarted
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
collaborations <- read_csv("Desktop/RWorkingDirectory/Working Directory/collaboration_edgelist_2012_2020.csv")
## Rows: 605 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Artist_1, Artist_2
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Merge artist information with collaboration data
collaborations_info <- merge(collaborations, artists, by.x = "Artist_1", by.y = "Artist", all.x = TRUE)
collaborations_info <- merge(collaborations_info, artists, by.x = "Artist_2", by.y = "Artist", all.x = TRUE, suffixes = c("_1", "_2"))
# Create a network object
collab_network <- network(collaborations_info[, c("Artist_1", "Artist_2")])
# Count collaborations for each artist
collab_counts <- collaborations_info %>%
group_by(Artist_1) %>%
summarise(total_collabs = n()) %>%
arrange(desc(total_collabs))
# Select the artist with the most collaborations
top_artist <- collab_counts$Artist_1[1]
# Filter collaborations data for the top artist
collaborations_top_artist <- collaborations_info %>%
filter(Artist_1 == top_artist | Artist_2 == top_artist)
# Create a network object
collab <- network(collaborations_top_artist[, c("Artist_1", "Artist_2")])
# Add attributes to the network
collab %v% "gender_1" <- artists$Gender[match(collab %v% "vertex.names", artists$Artist)]
collab %v% "gender_2" <- artists$Gender[match(collab %v% "vertex.names", artists$Artist.1)]
## Warning: Unknown or uninitialised column: `Artist.1`.
# Create network graph for top artist collaborations
net_collab <- ggnetwork(collab, layout = "fruchtermanreingold")
plot <- ggplot(net_collab, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(alpha = 0.5) +
geom_nodes(aes(color = factor(gender_1), size = 2)) +
geom_text_repel(data = net_collab$data, aes(label = vertex.names), size = 3) +
theme_void() +
scale_color_manual(values = c("0" = "lightblue3", "1" = "pink2"), name = "Gender") +
labs(title = paste("Collaborations Network for", top_artist),
subtitle = "Nodes represent artists | Edges represent collaborations") +
theme(legend.position = "bottom")
print(plot)
## Warning: ggrepel: 33 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps

Aesthetic Choices:
Node Color: The color of the nodes is used to represent the gender of the artists. Female artists (coded as 1) are depicted in pink ("pink2"), while male artists (coded as 0) are represented in light blue ("lightblue3"). This choice makes the gender information visually distinct and easy to interpret.
Edge Transparency (`geom_edges(alpha = 0.5)'): The edges connecting nodes have a transparency level of 0.5. This choice helps visualize overlapping edges in the network, providing a clearer view of collaboration connections without overwhelming the plot with too much information.
A legend is added to the plot to provide information about the color mapping. It indicates that pink represents female artists ("1") and light blue represents male artists ("0"`).
Clean Background: The background is kept void, removing unnecessary elements and focusing attention on the network structure. This minimalist approach contributes to a cleaner and more aesthetically pleasing visualization.
collab_network %v% "grammy_1" <- artists$GrammyWinner[match(collab_network %v% "vertex.names", artists$Artist)]
collab_network %v% "grammy_2" <- artists$GrammyWinner[match(collab_network %v% "vertex.names", artists$Artist)]
# Create network graph for Grammy winners with color
net_grammy_winners <- ggnetwork(collab_network, layout = "fruchtermanreingold")
plot_grammy_winners <- ggplot(net_grammy_winners, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(aes(color = factor(grammy_1)), alpha = 0.5, size = 0.5) +
geom_nodes() +
geom_text_repel(data = net_grammy_winners$data, aes(label = vertex.names), size = 3) +
theme_void() +
scale_color_manual(values = c("0" = "red", "1" = "gold2"), name = "Grammy Winner") +
labs(title = "Collaborations Network by Grammy Winners",
subtitle = "Nodes represent artists, edges represent Grammy winners",
size = "Edge Color: Grammy Winner") +
theme(legend.position = "bottom")
## 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.
print(plot_grammy_winners)
## Warning: ggrepel: 776 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps

Edge Color: The color of the edges represents whether the artist is a Grammy winner. Edges connected to Grammy-winning artists are colored in gold ("gold2"), while edges connected to non-Grammy winners are colored in red. This choice helps highlight the collaborations involving Grammy-winning artists.
Edge Size: Maintains a balanced and clear representation of edges without dominating the plot.
Artist names are added as text labels to the nodes using geom_text_repel` to ensure that labels do not overlap, enhancing readability.
Node Size: The size of the artist name labels is set to 3 for readability. This size ensures that the artist names are large enough to be easily seen while not dominating the plot.
A legend is included to explain the color mapping. It indicates that gold represents Grammy winners ("1") and red represents non-Grammy winners ("0"`).