[R] Barplot for degree distribution

Dennis Murphy djmuser at gmail.com
Wed Apr 27 05:15:40 CEST 2011


Hi:

Firstly, you should have mentioned that you were using the igraph
package; with over 2700 R packages available on CRAN, it's
unreasonable to expect folks to know to which package a particular
function resides, but you may not have been aware of that fact. It
turns out that dd1 is a numeric vector, so you can assign names to the
values which will be passed to barplot(); e.g.,

library(igraph)
g = barabasi.game(500, 0.4)
dd1 = degree.distribution(g)
# by default, produces an index plot
plot(dd1, xlab="degree", ylab = "frequency")
> str(dd1)
 num [1:19] 0 0.622 0.148 0.078 0.064 0.038 0.02 0.012 0.006 0.002 ...

# Assign labels to the values in dd1:
names(dd1) <- 0:18
barplot(dd1, xlab = "degree", ylab = "frequency", cex.names = 0.8,
            cex.axis = 0.8, xlab = 'Degrees', ylab = 'Relative frequency')

You can replace the values I assigned above with what works for your
application. To see why I lowered the font sizes with cex*, remove
them and you should see gaps between certain numbers on the horizontal
axis. If you need the larger font sizes, look into the staxlab()
function in the plotrix package for an alternative approach to
labeling.

HTH,
Dennis

On Tue, Apr 26, 2011 at 3:51 PM, kparamas <kparamas at asu.edu> wrote:
> In barplot for degree distribution x-axis is not seen.
>
> See the example below
>> g = barabasi.game(500, 0.4)
>> dd1 = degree.distribution(g)
>> plot(dd1, xlab="degree", ylab = "frequency")
>
> whereas barplot doesnot have any x-axis
>> barplot(dd1, xlab = "degree", ylab = "frequency")
>
> Please see the figures attached.
> http://r.789695.n4.nabble.com/file/n3476831/barplot_dd__one_.png
> http://r.789695.n4.nabble.com/file/n3476831/plot_dd__one_.png
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Barplot-for-degree-distribution-tp3476831p3476831.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list