Home > Software engineering >  How to turn summarized product into chart
How to turn summarized product into chart

Time:10-08

I am very new to R and have learned only the basics. I have created this code, which works fine, but I'd like to turn this into a chart:

all_data_clean %>% 
  group_by(month,member_casual) %>% 
  summarize(ave_trip=mean(trip_time))

Is there a way to add this summarization to a ggplot code? I keep getting errors when I try to add it. If not, what would my other options be for getting this data into a chart?

Thank you!!

CodePudding user response:

We just need

library(dplyr)
library(ggplot2)
all_data_clean %>% 
  group_by(month = factor(month, levels = month.name),member_casual) %>% 
  summarize(ave_trip=mean(trip_time), .groups = 'drop') %>%
  ggplot(aes(x = month, y = ave_trip, fill = member_casual)) %>%
     geom_col()
  •  Tags:  
  • r
  • Related