1

I have a generated a data set with power law distribution using poweRlaw package with the following code:

library("poweRlaw")
xmin = 1; alpha = 1.5
con_rns = rplcon(1000, xmin, alpha)

How can I get a log-log plot where x-axis is showing log(m) and y-axis showing log(freq(m)) for all m in the dataset?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
ahb65
  • 191
  • 2
  • 13

2 Answers2

1

I recommend the ggplot2 package because it is easy to learn, versatile, and widely used.

#your code
library("poweRlaw")
xmin = 1; alpha = 1.5
con_rns = rplcon(1000, xmin, alpha)

#loading ggplot2
require(ggplot2)

#convert to data.frame format for ggplot2
df <- as.data.frame(con_rns)

#make plot with both axes log scale
ggplot(data = df, aes(x = con_rns)) + 
    geom_line(stat = 'bin', binwidth = 0.1) + 
    scale_x_log10() + 
    scale_y_log10()
Curt F.
  • 4,690
  • 2
  • 22
  • 39
1

I got the solution:

library("poweRlaw")
xmin = 1; alpha = 1.5
x = rplcon(1000, xmin, alpha)
h <- hist(x, plot=F, breaks=c(seq(0,max(x)+1, .1)))
plot(h$counts, log="xy", pch=20, col="blue",xlab="Value", ylab="Frequency")

enter image description here

ahb65
  • 191
  • 2
  • 13