【问题标题】:Grouping bar chart by filtered rows (R)按过滤行分组条形图 (R)
【发布时间】:2022-08-02 17:55:26
【问题描述】:

我想在分组条形图上显示时间序列数据。我从一列(x,y)中过滤了两个变量。不幸的是,我无法弄清楚如何将它们分组显示。

使用下面的代码将堆叠条形图:

library(ggplot2)
library(dplyr)

target <- c(\"x\", \"y\")
filtered_dat <- filter(dat, column %in% target)

ggplot(filtered_dat, aes(year, column)) + 
  geom_col(position = \"dodge\", stat = \"identity\", width = 0.7) + 
  geom_text(aes(label = column), colour = \"white\")

非常感谢您的帮助。

标签: r ggplot2 grouped-bar-chart


【解决方案1】:

群aes() 解决了这个问题。因此我不得不将它们与group = column 代码组合在一起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 2016-07-11
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    相关资源
    最近更新 更多