From bb68c49552f69b90ce840dbd7346fc76eb93e3e3 Mon Sep 17 00:00:00 2001 From: Ben Green Date: Fri, 18 Sep 2015 23:38:46 -0400 Subject: pretty plots! --- R Scripts/plot-power-law.R | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 R Scripts/plot-power-law.R (limited to 'R Scripts/plot-power-law.R') diff --git a/R Scripts/plot-power-law.R b/R Scripts/plot-power-law.R new file mode 100644 index 0000000..8cca228 --- /dev/null +++ b/R Scripts/plot-power-law.R @@ -0,0 +1,26 @@ +plot(1:max(degree(lcc)),degree.distribution(lcc)[-1], + log='xy',col='#377EB8',pch=20, + xlab='Degree', ylab='Number of Vertices', main='') + + +# plot and fit the power law distribution +# calculate degree +d = degree(graph, mode = "all") +dd = degree.distribution(graph, mode = "all", cumulative = FALSE) +degree = 1:max(d) +probability = dd[-1] +# delete blank values +nonzero.position = which(probability != 0) +probability = probability[nonzero.position] +degree = degree[nonzero.position] +reg = lm(log(probability) ~ log(degree)) +cozf = coef(reg) +power.law.fit = function(x) exp(cozf[[1]] + cozf[[2]] * log(x)) +alpha = -cozf[[2]] +print(paste("Alpha =", round(alpha, 3))) +# plot +print(d) +curve(power.law.fit, col = "red", add = T, n = length(d)) + + +# fit_power_law(lcc) -- cgit v1.2.3-70-g09d2