【问题标题】:How to extract bin numbers and percents from ggplot2?如何从 ggplot2 中提取 bin 编号和百分比?
【发布时间】:2014-07-21 21:15:28
【问题描述】:

我使用ggplot2 包绘制了以下直方图。我想将 bin 编号(如果可能,还包括截止值)和群组百分比(如您所见,我使用geom_histogram 来获取百分比而不仅仅是计数)作为表格

ggplot(fst_num, aes(x = b)) +
    geom_histogram(aes(y = (..count../sum(..count..))*100), binwidth = 3.5)

【问题讨论】:

    标签: r ggplot2 histogram


    【解决方案1】:

    这是你的做法:

    ggplot_build(p2)$data[[1]]
    

    【讨论】:

    • 嗨,这可能很好地解决了这个问题......但如果你能提供一些关于它如何工作以及为什么工作的解释会很好:) 不要忘记 - 有很多新手在 Stack Overflow 上,他们可以从你的专业知识中学到一两件事——对你来说显而易见的事情对他们来说可能并不那么明显。
    • 具体来说,当查看来自ggplot_build(p2)$data[[1]] 的打印输出时,x 列显示每个 bin 的计数,xmin 和 xmax 列表示 bin 的范围。
    猜你喜欢
    • 1970-01-01
    • 2016-06-19
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    相关资源
    最近更新 更多