【问题标题】:ggplot2: Issues with changing binwidth of stacked histogramggplot2:改变堆叠直方图的 binwidth 的问题
【发布时间】:2014-02-12 17:27:33
【问题描述】:

在更改使用 ggplot2 创建的堆叠直方图的 binwidth 时遇到问题。

它不会出错,但似乎忽略了 binwidth 设置。

ggplot(trade.a, aes(x=variable1,y=value ,fill=category)) + 
    geom_bar(stat = "identity", binwidth=c(0,300),position ='fill') + 
    xlim(0, 300) + 
    xlab("Variable1") + 
    ylab("Count") + 
    ggtitle("Category") + 
    scale_y_continuous(labels = percent_format()) + 
    theme_grey(base_size = 20)

有什么想法吗?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    geom_bar 内使用stat="identity" 意味着trade.a 中的数据已经被分箱和计数(这也通过指定指向trade.a 数据的y 美学来暗示)。 binwidthstat_bin 的参数(geom_bar 的默认统计信息),它为您进行聚合。 (此外,它只需要一个值;breaks 参数可以采用断点向量。)因此,要更改 trade.a 数据的分箱宽度,您需要返回进行分箱的步骤。或者从未合并的数据开始,并使用默认的statgeom_bar 指定binwidth

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 2016-08-11
      • 1970-01-01
      • 2014-06-22
      • 1970-01-01
      • 2021-02-01
      • 2014-03-12
      相关资源
      最近更新 更多