Re: [R] Barplot for degree distribution

From: Dennis Murphy <djmuser_at_gmail.com>
Date: Tue, 26 Apr 2011 20:15:40 -0700

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.
>



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. Received on Wed 27 Apr 2011 - 03:19:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Apr 2011 - 06:40:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive