【问题标题】:Set x axis values设置 x 轴值
【发布时间】:2021-07-20 12:04:02
【问题描述】:

ggplot2 的 x 轴中,我有从 2011 年到 2019 年的年份值。我希望在图中看到这些值

但是我收到这样的逗号分隔值

如何更改值以显示年份?

【问题讨论】:

  • 能否提供一个可重现的示例。
  • 您是否尝试将Year 列更改为因子?
  • @RonakShah 你是对的

标签: r ggplot2


【解决方案1】:

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

library(scales)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多