带有对数刻度和自定义间隔的直方图 [英] Histogram with Logarithmic Scale and custom breaks

查看:120
本文介绍了带有对数刻度和自定义间隔的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成R的直方图,其对数标度为y.目前我正在这样做:

I'm trying to generate a histogram in R with a logarithmic scale for y. Currently I do:

hist(mydata$V3, breaks=c(0,1,2,3,4,5,25))

这给了我一个直方图,但是0到1之间的密度是如此之大(相差一百万左右),以至于您几乎无法分辨出其他任何条形图.

This gives me a histogram, but the density between 0 to 1 is so great (about a million values difference) that you can barely make out any of the other bars.

然后我尝试做:

mydata_hist <- hist(mydata$V3, breaks=c(0,1,2,3,4,5,25), plot=FALSE)
plot(rpd_hist$counts, log="xy", pch=20, col="blue")

它为我提供了所需的内容,但底部显示的是1-6而不是0、1、2、3、4、5、25.它还将数据显示为点而不是条. barplot可以,但是我没有任何底轴.

It gives me sorta what I want, but the bottom shows me the values 1-6 rather than 0, 1, 2, 3, 4, 5, 25. It's also showing the data as points rather than bars. barplot works but then I don't get any bottom axis.

推荐答案

直方图是穷人的密度估计值.请注意,在使用默认参数调用hist()时,您会得到频率而不是概率-如果需要概率,请在调用中添加,prob=TRUE.

A histogram is a poor-man's density estimate. Note that in your call to hist() using default arguments, you get frequencies not probabilities -- add ,prob=TRUE to the call if you want probabilities.

对于对数轴问题,如果您不希望对x轴进行转换,请不要使用'x':

As for the log axis problem, don't use 'x' if you do not want the x-axis transformed:

plot(mydata_hist$count, log="y", type='h', lwd=10, lend=2)

让您以对数级的角度获得标杆-外观仍然有些不同,但可能可以进行调整.

gets you bars on a log-y scale -- the look-and-feel is still a little different but can probably be tweaked.

最后,您还可以执行hist(log(x), ...)来获取数据日志的直方图.

Lastly, you can also do hist(log(x), ...) to get a histogram of the log of your data.

这篇关于带有对数刻度和自定义间隔的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆