r - R 中的 Monthplot - 如何更改默认轴,使其从 6 月而不是 1 月开始

标签 r timeserieschart

沿着 R {stats} 中月图的 x 轴从左到右阅读,我希望第一个月是 6 月(最后一个月是 5 月)。该轴默认为一月至十二月。我该如何进行更改?

我的月度生产数据时间序列中的第一个观察是六月,这是相关农业生产年度的开始。从 6 月开始,我已将数据格式化为 ts 类向量。

最佳答案

使用ggplot2,您可以使用scale_x_date来调整x(日期)轴的限制:

# Generate some sample data
set.seed(2017);
df <- data.frame(
    Date = seq(as.Date("2018-01-01"), by = "month", length.out = 24),
    Value = runif(24))

library(ggplot2);
ggplot(df, aes(Date, Value)) +
    geom_line() +
    scale_x_date(
        date_labels = "%b\n%Y",
        date_breaks = "2 month",
        limits = c(as.Date("2017-06-01"), as.Date("2019-05-31")))

enter image description here

关于r - R 中的 Monthplot - 如何更改默认轴,使其从 6 月而不是 1 月开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50920693/

相关文章:

java - 为什么时间序列集合图表中的数据显示不正确?

r - RcppArmadillo 和 Armadillo 之间的性能差异

r - 使用 R 循环遍历回归中的协变量

r - 基于一列向量的 data.table 到 long 重复另一列

r - R : Object not found 中的排序

javascript - highchart x 轴未显示正确的日期标签

javascript - Highcharts 时间序列组合图,其中几个月的数据为空

r - 如何为分组条形图在轴中添加中断?

r - 使用 ggplot2 从动物园对象绘制多线图

r - Plotly 时间序列 - 水平绘制线