并排栏图的解决方案错误:只能具有X或Y美学
我在用包含字符(ride_month)的列的并排条形图时遇到了困难,该列包含骑手两种类型的总数数据(ride_duration)(ride_duration)(构件_casual)。
ggplot(data=bike_data_v4)+
+ geom_bar(mapping = aes(x=ride_month,fill=member_casual))+
+ geom_col(position = "dodge")
Error in `check_required_aesthetics()`:
! geom_col requires the following missing aesthetics: x and y
Run `rlang::last_error()` to see where the error occurred.
为了解决我的问题,我做了一个新的数据集分组成员_casual和ride_month。接下来,我给了一笔骑行的总和。
bike_data_removedcols_V2 <- bike_data_removedcols %>%
group_by(member_casual, ride_month) %>%
summarise(ride_duration_sum=sum(ride_duration))
我采用了新创建的数据集并将其应用于此GGPLOT函数:
ggplot(data = bike_data_removedcols_V2, aes(ride_month, ride_duration_sum, fill=member_casual, group = member_casual))+
geom_col(position = position_dodge())
I was having trouble making a side-by-side bar graph with a column containing characters (ride_month), a column containing the total numeric data (ride_duration) for rider two types(member_casual).
ggplot(data=bike_data_v4)+
+ geom_bar(mapping = aes(x=ride_month,fill=member_casual))+
+ geom_col(position = "dodge")
Error in `check_required_aesthetics()`:
! geom_col requires the following missing aesthetics: x and y
Run `rlang::last_error()` to see where the error occurred.
my dataset originally looked like this:
To fix my problem, I made a new dataset grouping member_casual and ride_month. Next, I piped a sum of ride_duration.
bike_data_removedcols_V2 <- bike_data_removedcols %>%
group_by(member_casual, ride_month) %>%
summarise(ride_duration_sum=sum(ride_duration))
I took the newly created dataset and applied it to this ggplot function:
ggplot(data = bike_data_removedcols_V2, aes(ride_month, ride_duration_sum, fill=member_casual, group = member_casual))+
geom_col(position = position_dodge())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要具有分组的条形图,请添加
group
这样的美学:以下是
mtcars
dataset的示例:If you want to have a grouped bar chart then add
group
aesthetics like this:Here is an example with
mtcars
dataset:这会做你想要的吗?
Does this do what you want?