Search code examples
rggplot2grouped-bar-chart

Make a grouped barplot from count value in ggplot?


Good day everyone, I'm working with a fairly large dataset and am attempting to make a grouped barplot using ggplot2 in R. I'm struggling trying to divide my plot. I want to get the count for each month by the different types of members.

So far this is my code

bike_rides %>%  
  group_by(member_casual, month_of_use) %>%  
  summarize(Count = n()) %>% 
  ggplot(aes(x=month_of_use, y=Count)) + 
  geom_bar(aes(fill=member_casual, stat="identity", position= "dodge")) 

This output produces this error: Screenshot

Farily new to R so please be patient with me, any feedback is greatly appreciated.

Thank you.


Solution

  • Was able to answer my question thanks to @Jon Spring, closing the aes sooner made the difference!

    bike_rides %>%  
      group_by(member_casual, month_of_use) %>%  
      summarize(Count = n()) %>% 
      ggplot(aes(x=month_of_use, y=Count, fill=member_casual)) + 
      geom_bar(stat='identity', position= "dodge")
    
    

    New Graph

    Practice makes perfect!