ggplot2 failing to plot the y-axis properly

Dear members,

Kindly assist, I am struggling to produce a plot that shows average use duration of a bike share service each day of the week.

I am using the geom_bar option however the mapping function will not plot the y-axis properly

see code below

ggplot(data = Summary_weekday_with_count)+geom_bar(mapping = aes(x=day))

the object is below;

Summary_weekday_with_count<-cleaned %>%
select(rideable_type(trimmed),day, date,Duration_hrs_min_ss,Member_casual(trimmed)) %>%
group_by(day) %>%
drop_na() %>%

Summary_weekday_with_count$day<- as.factor(Summary_weekday_with_count$day)

Summary_weekday_with_count$day <- factor(Summary_weekday_with_count$day,
levels = c("Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))

You probably should use geom_col() instead of geom_bar(). geom_bar counts how many times each group appears. geom_col() directly plots the values. Try

ggplot(data = Summary_weekday_with_count) + geom_col(mapping = aes(x=day, y = average_duration))
1 Like

and indeed it has worked, thank you very much!


This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.