trips_2021 %>%
ggplot(aes(x=factor(ride_month), fill = member_casual)) + geom_bar()+ #using factor() to display all x values
scale_y_continuous(labels= comma) +
geom_text(stat = "count", aes(label = ..count..), size = 2)+
theme(axis.text.x = element_text(angle = 90))+
labs(title='Count of bike rides by months in 2021', x= 'Month of ride', y = 'Count of rides')
In the above image, we can clearly see that in some months say Jan, feb, oct and nov the data labels are incorrect and reversed (image shows that members take more rides than casual but their data labels tell otherwise). Whereas with the following code
trips_2021 %>%
ggplot(aes(x=factor(ride_month), fill = member_casual)) + geom_bar(position = 'fill')+ #using factor() to display all x values
scale_y_continuous(labels= comma) +
geom_text(stat = "count", aes(label = ..count..), size = 2, position = 'fill')+
theme(axis.text.x = element_text(angle = 90))+
labs(title='Count of bike rides by months in 2021', x= 'Month of ride', y = 'Count of rides')
the plot is correct with correct data labels.
Why is this happening? Please explain!