除了主刻度线之外,如何向轴添加次刻度线? [英] How to add minor tick marks to an axis besides its main tick marks?
问题描述
我有两个问题.
- 我想知道如何添加 两个词,一个代替0",另一个代替10" 在 X 和 Y 轴上,同时保留轴上剩余的其余数字(即,1 到 9)?
- 如何在两个轴上添加小刻度线?
- I was wondering how I can add two words, one appearing in place of "0", the other appearing in place of "10" on the X and Y axes while preserving the rest of the remaining numbers on the axes (i.e., 1 thru 9)?
- How can I add minor tick marks to both axes?
这是我的 R 代码,没有成功:
plot(0:10,0:10,type="n",axes=FALSE,xlab="JBL",ylab="PRAC")
axis(side=1,at=c("AL",1,2,3,4,5,6,7,8,9,"BL"),las=1)
axis(side=2,at=c("CL",1,2,3,4,5,6,7,8,9,"DL"),las=1)
box()
推荐答案
对于第一个问题,您应该使用 labels
而不是 at
.阅读?axis
.
For the first question, you should use labels
not at
. Read ?axis
.
对于第二个,您可以在同一轴上调用 axis
或 Axis
两次,但使用 rug
更容易.它是 Axis
的包装函数.例如,您可以这样做:
For the second, you can call axis
or Axis
twice on the same axis, but using rug
is easier. It is a wrapper function for Axis
. For example, you can do:
plot(0:10, 0:10, axes = FALSE) ## `axes` is an argument to `plot.default`
axis(1, at = 0:10, labels = c("AL",1,2,3,4,5,6,7,8,9,"BL"))
rug(x = 0:9 + 0.5, ticksize = -0.01, side = 1)
axis(2, at = 0:10, labels = c("CL",1,2,3,4,5,6,7,8,9,"DL"))
rug(x = 0:9 + 0.5, ticksize = -0.01, side = 2)
您可以在其源代码中看到 rug
是如何工作的:
You can see how rug
works in its source code:
Axis(side = side, at = x, labels = FALSE, lwd = 0, lwd.ticks = lwd,
col.ticks = col, tck = ticksize, ...)
阅读 ?par
了解 tck
的工作原理.轴的默认 tck
为 -0.02,因此如果您想要一个更小的短轴",请将其设置为一半.在这里,符号表示方向.正值表示刻度指向图内,而负值表示刻度指向图外.
Read ?par
for how tck
works. The default tck
for an axis is -0.02, so if you want a smaller one for "minor axis", set it to half. Here, the sign means direction. Positive values give ticks pointing inside the plot, while negative ones give ticks pointing outside the plot.
这篇关于除了主刻度线之外,如何向轴添加次刻度线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!