! Aesthetics must be either length 1 or the same as the data (14): fill
This message is telling you that the plot is expecting your fill aesthetic parameter to be the same length as day_of_week and n (or just length 1), but it is not that length. I usually run into this error when I'm mixing applying multiple data frames of different row lengths, and mix things up.
I think the issue is in the fill parameter in your plot aesthetics. Your current code refers to "data$member_casual", which is pulling from data, your original data source. Instead, you want to refer to the first column of your summarized data.
In your summarizing the data section, there is an issue in the group_by function. You should refer to the variable name,
member_casual_data <- data %>%
group_by(member_casual) %>%
count(day_of_week)
Now, the first column of your summary table is "member_casual", which allows you to update your plot to
ggplot(
member_casual_data,
aes(x = day_of_week, y = n, fill = member_casual)
) +
geom_bar(stat = "identity", position = "dodge") +
labs(x = "day of week", y = "numbers") +
ggtitle("Comparing the number of rides between member and casual users in a year(2021/04 - 2022/03)") +
theme(plot.title = element_text(size = 11)) +
scale_x_continuous(breaks = seq(1,7,1), labels = week) +
scale_y_continuous(limits = c(0,1000000), labels = label_comma())