Home > database >  Grouping bar chart by filtered rows (R)
Grouping bar chart by filtered rows (R)

Time:08-02

I want to display time series data on a grouped bar chart. I filtered the two variables from one column (x, y). Unfortunately I can't figure out how to display them grouped.

Using the code below will stack the bars:

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")

Thank you very much for any help.

CodePudding user response:

The group aes() solves the problem. Therefore I had to group them with the group = column code.

  • Related