【发布时间】:2021-01-07 19:58:21
【问题描述】:
当您在 ggplot2 中绘制条形图时,y 轴标记会自动停止在低于最大值的中断处。 在图中,最后一个标签是 40,而我希望它向上舍入到下一个中断,即 50。
set.seed (52)
date<-data.frame(date=sample(seq(as.Date('2020-01-01'), as.Date('2020-01-31'), by="day"),1000,replace=TRUE))
ggplot(data=date)+
geom_bar(mapping=aes(x=date))
我知道添加 +scale_y_continuous(limits=c(0,50)) 将手动将图表设为 50,但我需要不断更改这部分代码。有没有办法在 ggplot 函数中动态执行此操作?
【问题讨论】:
-
尝试在代码的最后部分添加
scale_y_continuous(breaks = scales::pretty_breaks(15))!