Plotting Network using igraph

1. Explain the data fields. Choose the specific data fields that you want to use to build the network.

Dataset information This is who-trusts-whom network of people who trade using Bitcoin on a platform called Bitcoin OTC. Since Bitcoin users are anonymous, there is a need to maintain a record of users’ reputation to prevent transactions with fraudulent and risky users. Members of Bitcoin OTC rate other members in a scale of -10 (total distrust) to +10 (total trust) in steps of 1. This is the first explicit weighted signed directed network available for research.

Bitcoin OTC trust weighted signed network

Dataset statistics

  • Nodes 5,881

  • Edges 35,592

  • Range of edge weight -10 to +10

  • Percentage of positive edges 89%

Fields:

The Bitcoin OTC dataset includes the following fields:

  • SOURCE: ID of the node that initiated the rating (the rater).

  • TARGET: ID of the node being rated (the ratee).

  • RATING: The rating given by the source to the target, ranging from -10 (worst trustworthiness) to +10 (highest trustworthiness).

  • TIME: Timestamp of the rating, measured in seconds since the Epoch (Unix timestamp).

Fields for Network Construction:

  • Use SOURCE and TARGET to build the network (nodes and edges).

  • Use RATING as a weight for the edges to study the strength or polarity of the relationships.

2. Read the network data from csv files and display the data in a table in R.

# Load required libraries
library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
# Read CSV file
data <- read.csv("C:/UTM/Semester 2/SOCIAL NETWORK ANALYTICS/Assignment 1 (Part 2)/soc-sign-bitcoinotc.csv", header = FALSE, stringsAsFactors = FALSE)
colnames(data) <- c("SOURCE", "TARGET", "RATING", "TIME")

# Display the first few rows
head(data)

3. Plot the Network using igraph

# Create a graph object
graph <- graph_from_data_frame(d = data[, c("SOURCE", "TARGET")], directed = TRUE)

# Plot the network
plot(graph, vertex.size = 5, vertex.label = NA, edge.arrow.size = 0.5, main = "Bitcoin OTC Network")

4. Examine the data:

a. Find number of nodes
num_nodes <- vcount(graph)
cat("Number of nodes:", num_nodes, "\n")
## Number of nodes: 5881
b. Find number of edges
num_edges <- ecount(graph)
cat("Number of edges:", num_edges, "\n")
## Number of edges: 35592
c. Find the edgelist (“from”, “to”)
edge_list <- as_edgelist(graph)
head(edge_list)
##      [,1] [,2]
## [1,] "6"  "2" 
## [2,] "6"  "5" 
## [3,] "1"  "15"
## [4,] "4"  "3" 
## [5,] "13" "16"
## [6,] "13" "10"

5. Simplify the network by removing all the multiple edges and loops.

# Simplify network: Remove loops and multiple edges
simplified_graph <- simplify(graph, remove.multiple = TRUE, remove.loops = TRUE)

# Plot simplified graph
plot(simplified_graph, vertex.size = 7, edge.arrow.size = 0.5, main = "Simplified Transaction Network")

cat("Number of nodes:", vcount(simplified_graph), "\n")
## Number of nodes: 5881
cat("Number of edges:", ecount(simplified_graph), "\n")
## Number of edges: 35592