Skip to content

Barplot for degree distribution

4 messages · kparamas, Dennis Murphy, David Winsemius

#
In barplot for degree distribution x-axis is not seen.

See the example below
whereas barplot doesnot have any x-axis
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.
#
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")
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:
#
Thanks for the info.

I have 2 degree distributions that have different degrees.

I want both these barplots to have the same axes. Is this possible?
I have used xlim and ylim. ylim works fine for both plots
But xlim I am not getting the values till 60. And if I give names(dd) <-
0:60 it gives an error.

library(igraph)
names(dd1) <- 0:18
barplot(dd1, cex.names = 0.8, ylim = c(0, 0.3), xlim = c(0, 60)
            cex.axis = 0.8, xlab = 'Degrees', ylab = 'Relative frequency') 

names(dd2) <- 0:50
barplot(dd2, cex.names = 0.8, ylim = c(0, 0.3), xlim = c(0, 60)
            cex.axis = 0.8, xlab = 'Degrees', ylab = 'Relative frequency') 

--
View this message in context: http://r.789695.n4.nabble.com/Barplot-for-degree-distribution-tp3476831p3477191.html
Sent from the R help mailing list archive at Nabble.com.
#
On Apr 27, 2011, at 12:00 AM, kparamas wrote:

            
Do you mean a different range of values?
An error you say? .... WHICH ERROR?
Without the data, this will remain a difficult guessing exercise. My  
guess is that you have a column that you think is numeric but is  
really a factor.