英文:
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 <- 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()` using `bins = 30`. Pick better value with `binwidth`.
<!-- -->
ggplot(df.cs_overall, aes(x=cs_mean.score)) + geom_histogram(fill="#F0A9D7", binwidth = .25)
<!-- -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论