我有 14e^06 elements 的数字变量 "myvariable" ,我想绘制一个直方图来显示每个bin的相对频率 .
考虑以下示例数据:
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))
或者我们可以绘制 histogram of the relative frequency
require(ggplot2)
ggplot(wdata, aes(x = weight)) +
geom_histogram(aes(y = (..count..)/sum(..count..)))
现在,考虑我的真实数据:
temp
+ 218L, 4609L, 2173L, 5691L, 39296L)
myvariable
require(ggplot2)
mydf
ggplot(mydf, aes(x = myvariable)) +
geom_histogram(aes(y = (..count..)/sum(..count..)))
绘制相对频率直方图的过程变得无限慢,因此,唯一的选择是使用geom_density进行绘图,但这不是我需要的 .
我的问题是:
你能建议我一个更好的方法来获得我的数字变量的相对频率直方图吗?