R 海量数据集中数值变量的相对频率直方图

R 海量数据集中数值变量的相对频率直方图,r,histogram,percentage,numeric,R,Histogram,Percentage,Numeric,我有一个数值变量“myvariable”,包含14e^06元素,我想绘制一个柱状图来显示每个箱子的相对频率 考虑到以下样本数据: set.seed(1234) wdata = data.frame( sex = factor(rep(c("F", "M"), each=200)), weight = c(rnorm(200, 55), rnorm(200, 58))) 我们可以绘制正常频率直方图: require(ggplot2) ggplot(wdata,

我有一个数值变量
“myvariable”
,包含
14e^06元素
,我想绘制一个柱状图来显示每个箱子的相对频率

考虑到以下样本数据:

set.seed(1234)
wdata = data.frame(
        sex = factor(rep(c("F", "M"), each=200)),
        weight = c(rnorm(200, 55), rnorm(200, 58)))
我们可以绘制正常频率直方图:

require(ggplot2)

ggplot(wdata, aes(x = weight)) +
        geom_histogram(aes(color = sex))
或者我们可以绘制相对频率的直方图

require(ggplot2)

ggplot(wdata, aes(x = weight)) +
 geom_histogram(aes(y = (..count..)/sum(..count..)))
现在,考虑到我的真实数据:

temp <- c(291L, 2440L, 1317L, 67L, 2258L, 3992L, 202L, 224L, 6761L, 9671L, 
+        218L, 4609L, 2173L, 5691L, 39296L)
myvariable <- sample(temp, 14000000, replace = TRUE)
require(ggplot2)
mydf <- data.frame(myvariable)
    ggplot(mydf, aes(x = myvariable)) +
     geom_histogram(aes(y = (..count..)/sum(..count..)))

temp感谢您的编辑。问题是否清楚,或者我可以改进它以接收ASNWER?