在R图上添加自定义刻度线

时间:2012-12-02 14:11:29

标签: r plot

我正在绘制一些数据的cdf,并且我在“x”轴上添加了对数刻度。 刻度线间距与我想要的完全一样,但我希望能够添加 特定点上的一些刻度线。

我不想更改我的情节中的刻度线分布,从n by nm by m,我只想在n by n的刻度线中更改某些值上还有一些刻度线。

我想让它反映在xy轴上,以便我可以在整个图表中将网格放入这些新标记中。

到目前为止,我有图表和网格 - 我不介意将网格放在图形后面,我只是想添加一些自定义标记。

# Cumulative Distribuition
pdf("g1_3.pdf")

plot(x = f$V2, y = cumsum(f$V1), log = "x", pch = 3,
     xlab = "Frequency", ylab = "P(X <= x)",
     panel.first = grid(equilogs = FALSE))

axis(1, at = c(40, 150))
abline(h = 0.6, v = 40, col = "lightgray", lty = 3)
abline(h = 0.6, v = 150, col = "lightgray", lty = 3)

dev.off()

更新:到目前为止的图表:

enter image description here

1 个答案:

答案 0 :(得分:14)

考虑到初始脚本和@BenBolker给出的提示,我不得不使用:

axis(side = 1, at = c([all the ticks you want]))

以便在图表中添加ticks。这是最终结果:

# Cumulative Distribuition
pdf("g1_3.pdf")

plot(x = f$V2, y = cumsum(f$V1), log = "x", pch = 3,
     xlab = "Frequency", ylab = "P(X <= x)", axes = FALSE)

ticks = c(1, 5, 10, 40, 150, 500, 1000)
axis(side = 1, at = ticks)
axis(side = 2)

abline(h = seq(0, 1, 0.2), v = ticks, col = "lightgray", lty = 3)
box()

Final result to the graph I was trying to generate