1

我想在绘图的 x 轴上设置刻度线,以每 5 个刻度位置更改长度(从 0.015 到 0.02),但是 tck 不会接受多个值,有什么想法吗?这是我的代码示例:

year<-seq(1960,2010,1)

xlab.pos <- rep (NA, length (year))
xlab.pos [seq(1, length (xlab.pos), 5)] <- year [seq(1, length (year), 5)]

xlab.tck <- rep(0.015, length (year))
xlab.tck [seq(1, length (xlab.tck), 5)] <- 0.02

plot(0, 0, type = "n", xlab = "", ylab = "", xaxt = "n",
xlim = c(min(year), max(year)),ylim = c(0, 5000))

axis(1, at = seq(min(year),max(year),1), labels = xlab.pos, tck = xlab.tck)

但正如预期的那样,我得到了错误:图形参数“tck”的长度错误我不知道如何设置它。

4

1 回答 1

0

使用包Hmisc将帮助你。

library(Hmisc)
plot(0, 0, type = "n", xlab = "", ylab = "", xaxt = "n",
     xlim = c(min(year), max(year)),ylim = c(0, 5000))
axis(1, at = seq(min(year),max(year),1), labels = xlab.pos, tck = -0.015)
minor.tick(nx = 3, ny = 0, tick.ratio = -1/2)

不过,您需要做一些额外的调整!

于 2013-08-28T14:33:14.570 回答