0

I am struggling to customise the jump size on the x-axis in R.

Current code:

par(mfrow = c(2,2))

r.star.ts.sp <- ts(r.star.sp, frequency = 4, start = c(1978,1), end = c(2018, 1)) 
# Big drop in r* around 123th quarter equivalent to 2008:Q4 / 2009:Q1
trendgrowth.ts.sp <- ts(trendgrowth.sp, frequency = 4, start = c(1978,1), end = c(2018, 1))

plot.ts(r.star.ts.sp,
        ylim = c(-3, 4), xlab = " ", ylab = " ", axes = F, col = "blue")
lines(trendgrowth.ts.sp, lty = 2, col = "red")
abline(h = 0, lty = 2)

title(main ="r* and Trend Growth", line = 0.5, font.main = 3)
box()
axis(4)
axis(1)

legend("bottomleft", legend = c("r*", "Trend Growth (g)"), 
       bty = "n", lty = c(1,2), col = c("blue", "red"), horiz = F, text.col = "black", 
       cex = 1, pt.cex = .5, inset = c(0.02, 0.02))

# -------------------------------------- #
# Plot output gap and real rate gap
# -------------------------------------- #
outputgap.ts.sp <- ts(outputgap.sp, frequency = 4, start = c(1978,1), end = c(2018, 1))
realrategap.ts.sp <- ts(realrategap.sp, frequency = 4, start = c(1978,1), end = c(2018, 1))

plot.ts(outputgap.ts.sp, ylim = c(-20, 15), xlab=" ", ylab=" ", axes = F, col="blue")
lines(realrategap.ts.sp, lty = 2, col = "red")
abline(h = 0, lty = 2)

legend("topright", legend = c("Output Gap", "Real Rate Gap"), 
       bty = "n", lty = c(1,2), col = c("blue", "red"), horiz = F, text.col = "black", 
       cex = 1, pt.cex = .5, inset = c(0.02, 0.02))

title(main = "Output Gap and Real Rate Gap", line = 0.5, font.main = 3)
box()
axis(side = 4)
axis(side = 1)

How would one specify the years on the x-axis from 1975 to 2020 with jumps of 5 years?

Furthermore, (off-topic) I need two plots next to each other, but I feel that par(mfrow = c(2,2)) is not the correct statement. However, changing it into par(mfrow = c(1,2)) creates abnormal large figures.

Thanks!

4

1 回答 1

1

OP 已要求在 x 轴上指定从 1975 年到 2020 年的年份,跳跃为 5 年

这可以通过

axis(1, at = seq(1975L, 2020L, by = 5L))

但是,结果可能取决于mfrow参数。这是一个使用的虚拟示例par(mfrow = c(2, 2))

在此处输入图像描述

请注意,左图的 x 轴是由 创建的,axis(1)而右图的 x 轴是由创建的axis(1, at = seq(1975L, 2020L, by = 5L))。还要注意两个图表下方的大空白区域。

结果par(mfrow = c(1, 2))变成

在此处输入图像描述

在这里,右图显示了未标记的(“次要”)刻度线。这在以下mfrow部分进行了解释?par在恰好有两行和两列的布局中,“cex”的基值减少了 0.83 倍。因此,字体大小减少了 17%,这允许标记所有刻度线而不会过度绘制。

于 2018-06-30T21:48:43.660 回答