r - 直方图未显示正确的计数/值?(直方图 vs Geom Freqpoly)
问题描述
我有 2002 年纽约马拉松赛和每个人的地点的数据集。我也有每个人的性别。
当我绘制一个按性别分组的直方图时,女性的计数关闭了!
当我绘制 FreqPoly 图时,分布与基于数据的预期一致。
谁能解释这种差异?红色条用于女性,蓝色条用于男性。相同的颜色适用于 freq_poly 图。
解决方案
不是答案,而是 Ian Campbell 和 teunbrand 的答案中讨论的不同职位选项的可视化
library(ggplot2)
set.seed(1)
p1 <- ggplot()+
geom_histogram(data = data.frame(x = rnorm(100), g = rep(1:2, 50)), aes(x, fill = factor(g)), position = "dodge")+
ggtitle("position = dodge")
set.seed(1)
p2 <- ggplot()+
geom_histogram(data = data.frame(x = rnorm(100), g = rep(1:2, 50)), aes(x, fill = factor(g)), position = "identity")+
ggtitle("position = identity")
set.seed(1)
p3 <- ggplot()+
geom_histogram(data = data.frame(x = rnorm(100), g = rep(1:2, 50)), aes(x, fill = factor(g)))+
ggtitle("position = stack")
library(patchwork)
p1/p2/p3
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
由reprex 包于 2020-07-11 创建(v0.3.0)
推荐阅读
- c++ - 复制数据结构,WM_COPYDATA
- ubuntu - Ubuntu,Docker-proxyconnect tcp:tls:收到长度为 20527 的超大记录
- sql - 使用用户定义的函数和左加入 oracle 10g 的分页速度很慢
- google-api-java-client - 在 Google Apps Marketplace API 中获取“未授权访问应用程序 ID”
- opengl-es-2.0 - 如何在 GLES2 中加载 BGRA 图像纹理?
- android - 应用插件 com.android.application 失败
- c# - Azure 配置的 APPINSIGHTS_INSTRUMENTATIONKEY 和 ApplicationInsights:InstrumentationKey 有什么区别?
- php - 哪位大侠能告诉我smtp & godaddy的秘密?
- firebase - Firebase 崩溃报告和 crashlytics 都可以使用吗
- angular - 如何通过更改角度 5 中的 scss 文件来停止自动重建应用程序?