在R图中调整x轴和文本之间的距离

时间:2016-04-22 00:51:34

标签: r plot

在下图中,您可能会发现x-aixs与日期(Jan-01-60至Mar-31-16)之间的距离很大。

Plot of a time series data

无论如何我可以缩小距离吗?

这是我的示例代码:

plot(dates, data, type = "l", lwd = 3, ylab = " ", 
     xlab = " ", col = "gray35", xaxt='n', ann = FALSE)
axis(side=1, at=dates_ten, labels=format(dates_ten, "%b-%d-%y"), las =     
     1, cex.axis=0.5, las = 1, font = 2, tcl = -0.2)

非常感谢。

1 个答案:

答案 0 :(得分:1)

您可以将padj参数用于axis

# make a reproducible example 
dates <- seq(as.Date("2016/1/1"), as.Date("2016/4/1"), "days")
dates_ten <- seq(as.Date("2016/1/1"), as.Date("2016/4/1"), "10 days")
set.seed(42)
data <- rnorm(seq_along(dates))

根据需要改变padj

plot(dates, data, type = "l", lwd = 3, ylab = " ", 
     xlab = " ", col = "gray35", xaxt='n', ann = FALSE)
axis(side=1, at=dates_ten, labels=format(dates_ten, "%b-%d-%y"), las = 1,
     cex.axis=0.5, las = 1, font = 2, tcl = -0.2, padj = -2)

enter image description here