在R中设置直方图的x轴以表示随机变量的真实域很困难

在R中设置直方图的x轴以表示随机变量的真实域很困难,r,histogram,R,Histogram,我刚刚意识到,在直方图中,x轴上只有索引值,而不是预期的0到5范围: 从逻辑上讲,我已经搜索并找到了一些相关的帖子,如和,并尝试了类似的事情 x1 = 5 # Maximum value x0 = 0.1 # It can't be zero; otherwise X^0^(neg) is 1/0. alpha = -2.5 # It has to be negative. y = runif(1e5) # Number of samples x

我刚刚意识到,在直方图中,x轴上只有索引值,而不是预期的0到5范围:

从逻辑上讲,我已经搜索并找到了一些相关的帖子,如和,并尝试了类似的事情

x1 = 5           # Maximum value
x0 = 0.1         # It can't be zero; otherwise X^0^(neg) is 1/0.
alpha = -2.5     # It has to be negative.
y = runif(1e5)   # Number of samples
x = ((x1^(alpha+1) - x0^(alpha+1))*y + x0^(alpha+1))^(1/(alpha+1))

h = hist(x, prob=T, breaks=40, plot=F)
plot(h$count, log="xy", type='l', lwd=1, lend=2, 
xlab="", ylab="", xaxt = 'n', main="Density in logarithmic scale")
axis(side=1, at=seq(0, 5, .2), labels=seq(0, 5, .2))
获得非感官结果:

你可能在寻找密度


注:set.seed42.

谢谢。你知道如何生成具有相同x轴的直方图吗?@Toni我猜你的意思是x轴也应该是对数的?不,那很好,log=y或log=xy。。。我问的是完全避免使用密度函数——尽管这是最好的选择——并使用hist进行同样的离散化或装箱。@Toni我不确定其好处,hist也计算密度,而lines函数则在箱子上进行平滑处理?然而,我们可能应该更多地注意从、到等。密度参数。
x1 = 5           # Maximum value
x0 = 0.1         # It can't be zero; otherwise X^0^(neg) is 1/0.
alpha = -2.5     # It has to be negative.
y = runif(1e5)   # Number of samples
x = ((x1^(alpha+1) - x0^(alpha+1))*y + x0^(alpha+1))^(1/(alpha+1))

h = hist(x, prob=T, breaks=40, plot=F)
plot(h$count, log="xy", type='l', lwd=1, lend=2, 
xlab="", ylab="", xaxt = 'n', main="Density in logarithmic scale")
axis(side=1, at=seq(0, 5, .2), labels=seq(0, 5, .2))
plot(density(x), log="y", ylab="log density x", col=2)
legend("topright", "x", lty=1, col=2)