首页 > 解决方案 > 设置 x 轴值

问题描述

ggplot2x 轴上,我有从 2011 年到 2019 年的年份值。我希望在图中看到这个值

但是我收到这样的逗号分隔值 在此处输入图像描述

如何更改值以显示年份?

标签: rggplot2

解决方案


我的猜测:scale_x_date。如果您的日期是日期格式,请将这行代码添加到您的 ggplot 代码中:

library(scales)

  scale_x_date(labels = date_format("%Y"))

推荐阅读