-
Notifications
You must be signed in to change notification settings - Fork 0
/
Degree Distribution Comparison
34 lines (25 loc) · 3.97 KB
/
Degree Distribution Comparison
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(igraph)
# Trait IDs
file_numbers <- c( 9, 10, 11, 13, 41, 46, 53, 61, 62, 63, 67, 68, 69, 70, 71, 72, 73, 74, 94, 95, 96, 108, 113, 118, 126, 127, 142, 143, 146, 155, 156, 161, 162, 167, 168, 173, 174, 191, 193, 206, 208, 1004, 1067, 1193, 1194, 1202, 1203, 1204, 2024, 2029, 2030, 2031, 2034, 2037, 2052, 2175, 3185, 3186, 3187, 3188, 3190, 3191, 3195, 3200, 3201, 3210, 3217, 3219, 3220, 3228, 3229, 3230, 3231, 3232, 3233, 3236, 3241, 3242, 3244, 3246, 3250, 3251, 3253, 3254, 3255, 3256, 3257, 3258, 3261, 3270, 3271, 3273, 3274, 3275, 3276, 3282, 3283, 3284, 3285, 3286, 3287, 3288, 3289, 3290, 3291, 3292, 3300, 3301, 3304, 3305, 3307, 3308, 3310, 3312, 3313, 3314, 3315, 3319, 3324, 3328, 3332, 3339, 3340, 3342, 3343, 3366, 3372, 3379, 3380, 3409, 3412, 3413, 3414, 3415, 3417, 3418, 3425, 3431, 3435, 3436, 3437, 3438, 3440, 3441, 3442, 3443, 3444, 3445, 3446, 3447, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460, 3461, 3462, 3463, 3464, 3465, 3466, 3467, 3468, 3469, 3470, 3471, 3485, 3494, 3495, 3496, 3497, 3498, 3499, 3500, 3503, 3529, 3531, 3539, 3544, 3549, 3551, 3552, 3553, 3554, 3555, 3559, 3570, 3578, 3590, 3591, 3597, 3599, 3601, 3602, 3605, 3606, 3608, 3613, 3625, 3654, 3658, 3660, 3665, 3668, 3685, 3686, 3688, 3691, 3695, 3785, 3789, 3791, 3793, 3794, 3795, 3797, 3798, 3815, 3818, 3819, 3820, 3822, 3823, 3824, 3832, 3833, 3834, 3835, 3836, 3837, 3838, 3839, 3840, 3841, 3842, 3843, 3844, 3845, 3846, 3847, 3848, 3849, 3850, 3851, 3852, 3853, 3854, 3855, 3856, 3857, 3858, 3859, 3860, 3861, 3862, 3863, 3864, 3865, 3866, 3867, 3868, 3869, 3870, 3871, 3872, 3873, 3874, 3875, 3876, 3877, 3878, 3879, 3880, 3881, 3882, 3883, 3884, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3894, 3895, 3896, 3897, 3898, 3899, 3900, 3901, 3902, 3903, 3904, 3908, 3910, 3925, 3939, 3943, 3966, 3967, 3968, 3971, 3979, 3982, 3990, 3991, 3992, 3993, 3994, 3995, 3996, 3997, 3999, 4002, 4011, 4018, 4038, 4040, 4043, 4044, 4045, 4050, 4063, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 4074, 4075, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4085, 4086, 4087, 4091, 4092, 4093, 4094, 4098, 4099, 4100, 4101, 4104, 4106, 4107, 4108, 4109, 4110, 4111, 4119, 4120, 4121, 4122, 4126, 4129, 4135, 4138, 4139, 4140, 4141, 4142, 4144, 4166, 4167, 4175, 4176, 4178, 4181, 4183, 4184, 4187, 4200, 4205, 4206, 4207, 4208, 4215, 4217, 4221, 4222, 4223, 4224, 4225, 4226, 4227, 4232, 4235, 4236, 4266, 4267, 4268, 4269, 4272, 4275, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4290, 4293, 4294, 4295, 4299, 4301, 4302, 4303, 4304, 4305, 4306, 4307, 4308, 4309, 4311, 4314, 4315, 4317, 4321, 4322, 4325, 4326, 4327, 4328, 4345, 4346, 4347, 4348, 4351, 4352, 4357, 4358, 4361, 4363, 4365, 4372, 4377, 4378)
plot_degree_distribution <- function(num, main_title) {
file_path_A <- paste0("file path/adj_matrix_col_num_", num, ".csv")
file_path_N <- paste0("file path/adj_matrix_n_col_num_", num, ".csv")
adj_matrix_A <- as.matrix(read.csv(file_path_A, header = TRUE, row.names = 1))
adj_matrix_N <- as.matrix(read.csv(file_path_N, header = TRUE, row.names = 1))
g_A <- graph_from_adjacency_matrix(adj_matrix_A, mode = "undirected", weighted = TRUE)
g_N <- graph_from_adjacency_matrix(adj_matrix_N, mode = "undirected", weighted = TRUE)
degrees_A <- degree(g_A)
degrees_N <- degree(g_N)
dist_A <- table(degrees_A)
dist_N <- table(degrees_N)
png(paste0("degree_distribution_comparison_", num, ".png"), width = 800, height = 600)
plot(as.numeric(names(dist_A)), as.numeric(dist_A), type = "o", col = "red", lwd = 3, ylim = c(0, 400),
xlab = "Degree", ylab = "Frequency", main = main_title, xlim = c(0, 27))
lines(as.numeric(names(dist_N)), as.numeric(dist_N), type = "o", col = "blue", lwd = 2, lty = 2)
legend("topright", legend = c("Degree Distribution A", "Degree Distribution N"),
col = c("red", "blue"), lwd = c(3, 2), lty = c(1, 2))
dev.off()
}
for (num in file_numbers) {
plot_degree_distribution(num, paste("Degree Distribution Comparison for num =", num))
}