在 ggplot 中移动 y 刻度,geom_col

Moving the y scale in ggplot, geom_col

我希望我列出的最低 y 刻度数字位于图表底部。当我 运行 代码时,最小的数字在图表的中间。

数据框:

|casual_member|weekday|number_of_rides|average_duration|
|-------------|-------|---------------|----------------|
|casual       |Sun    |333451         |23.95861 mins   |
|casual       |Mon    |197285         |22.00945 mins   |
|casual       |Tue    |192038         |20.70753 mins   |
|casual       |Wen    |203911         |20.27327 minss  |
|casual       |Thu    |209860         |20.06790 mins   |
|casual       |Fri    |274578         |21.13946 mins   |
|casual       |Sat    |421152         |23.24371 mins   |
|casual       |Sun    |309201         |15.96388 mins   |
|casual       |Mon    |328976         |13.87167 mins   |
|casual       |Tue    |357244         |13.75974 mins   |
|casual       |Wen    |381470         |13.76543 mins   |
|casual       |Thu    |367625         |13.69283 mins   |
|casual       |Fri    |374362         |14.05773 mins   |
|casual       |Sat    |370914         |15.67448 mins   |

代码

    ggplot(data = all_trips_v3)+
    geom_col(aes(x= weekday, y=number_of_rides, fill = member_casual),
             position = "dodge")+
    ggtitle("Total Weekday Rides of Casuals and Members")+
    scale_y_continuous(breaks = c(150000, 200000, 250000, 300000,
                                  350000, 400000, 450000), 
                       name = "Number of Rides")+
    scale_x_discrete (name = "Weekday")

如何让 150000 位于图表底部?

我尝试了以下方法,代码从我的图表中删除了条形图:

    scale_y_continuous(limits = c(150000,450000), name = "Number of Rides") 
    scale_y_discrete(name = "Number of Rides")+ scale_x_discrete (name = "Weekday")+ ylim(150000, 450000)

所以 ylim() 删除了绘图限制之外的数据。 相反,尝试添加 coord_cartesian 以放大情节:

coord_cartesian(ylim = c(150000, 450000))