[英]R- double-log density plot
I have a generated a data set with power law distribution using "poweRlaw" package with the following code: 我使用“ poweRlaw”包和以下代码生成了具有幂律分布的数据集:
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? 如何获得数据集中所有m的x轴显示log(m)和y轴显示log(freq(m))的对数对数图?
I recommend the ggplot2
package because it is easy to learn, versatile, and widely used. 我建议使用
ggplot2
软件包,因为它易于学习,用途广泛且用途广泛。
#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()
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.