简体   繁体   English

用 R 以对数刻度(以 10 为底)绘制分布的密度线

[英]Plotting density lines of distributions in log-log scale (base 10) with R

I know about the parameter log="xy" , but I don't know whether you can control the base of the logarithmic scale (my guess is that 10 may be the default (?)), and I'm not getting lucky on the specific issue below...我知道参数log="xy" ,但我不知道您是否可以控制对数标度的基数(我的猜测是 10 可能是默认值(?)),而且我不走运下面的具体问题...

How can I reproduce the following plot ( from this source ) with R. In particular, I am having problems with the log base 10 x and y axes.如何使用 R 重现以下图( 来自此来源)。特别是,我在对数基数 10 x 和 y 轴上遇到问题。

在此处输入图片说明

Leaving aside the power law red line, I was playing with撇开幂律红线不谈,我在玩

x = rlnorm(1e4,0,10)
h = hist(x, prob=T, plot=F)
plot(h$count, log="xy", type="l", lend=2)

without success.没有成功。

Use the pdf of the lognormal in base10使用 base10 中对数正态的 pdf

在此处输入图片说明

[Generalising it to other log-bases is straightforward.] [将其推广到其他日志库很简单。]

We can then plot the pdf on a log10-log10 scale.然后我们可以在 log10-log10 尺度上绘制 pdf。

(gg)plotting (gg) 绘图

# lognormal base log10 pdf, w is in log10
lognorm_base10 <- function(w, mu, sigma) {
    log10(exp(1)) / (sqrt(2*pi*sigma^2) * 10^w) * exp(- (w - mu)^2 / (2 * sigma^2));
}

# Generate data for mu = 0, sigma = 10 
x <- seq(0, 10, length.out = 100);
y <- lognorm_base10(x, 0, 10);

# Plot
require(ggplot2);
gg <- ggplot(data.frame(x = x, y = y), aes(x, y));
gg <- gg + geom_line() + scale_y_log10();
gg <- gg + labs(x = "log10(x)", y = "log10(p)")

在此处输入图片说明

Plotting without ggplot没有ggplot的绘图

plot(x, log10(y), type = "l")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM