为什么直方图看起来像那样?

huangapple go评论90阅读模式
英文:

Why does the histogram look like that?

问题

我感觉我应该知道这个,就像我的大脑里有一个结。

我有这样的数据:

有一个刻度从1、1.25、1.5、1.75、2、2.25、2.5、2.75、3等等,对于每个刻度点,有一定数量的人选择了它 - 没有一个数据点是0。

然而,直方图看起来像这样,中间有奇怪的空隙。为什么呢?

谢谢!

为什么直方图看起来像那样?

英文:

I feel like I should know this and like I have a knot in my brain.
I have data that looks like this:

there a scale going 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3 etc and for each scale point there's a certain number of people who selected it - none of the data points is 0.

Yet, the histogram looks like this with the weird spaces in between. Why?

Thank you!

为什么直方图看起来像那样?

答案1

得分: 1

可能是你只需要适当地设置你的binwidth
这里有一个使用模拟数据的示例,首先是标准的binwidth,然后是binwidth为0.25:

library(tibble)
library(dplyr)
library(ggplot2)

df.cs_overall <- tibble(cs_mean.score = sample(seq(0,5,.25), 500, T))

ggplot(df.cs_overall, aes(x=cs_mean.score)) + geom_histogram(fill="#F0A9D7")
#> `stat_bin()` 使用 `bins = 30`。使用 `binwidth` 选择更好的值。

为什么直方图看起来像那样?

ggplot(df.cs_overall, aes(x=cs_mean.score)) + geom_histogram(fill="#F0A9D7", binwidth = 0.25)

为什么直方图看起来像那样?

英文:

It might be that you just need to set your binwidth appropriately.
Here is an example using simulated data, first with the standard binwidth, second with a binwidth of .25:

library(tibble)
library(dplyr)
library(ggplot2)

df.cs_overall &lt;- tibble(cs_mean.score = sample(seq(0,5,.25), 500, T))


ggplot(df.cs_overall, aes(x=cs_mean.score)) + geom_histogram(fill=&quot;#F0A9D7&quot;)
#&gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

为什么直方图看起来像那样?<!-- -->



ggplot(df.cs_overall, aes(x=cs_mean.score)) + geom_histogram(fill=&quot;#F0A9D7&quot;, binwidth = .25)

为什么直方图看起来像那样?<!-- -->

huangapple
  • 本文由 发表于 2023年3月15日 18:44:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定