更改绘图轴上刻度线的间距? [英] Change the spacing of tick marks on the axis of a plot?
问题描述
如何更改绘图轴上刻度线的间距?
How can I change the spacing of tick marks on the axis of a plot?
我应该在基本图或rgl
中使用哪些参数?
What parameters should I use with base plot or with rgl
?
推荐答案
在基础图中至少有两种方法可以实现此目的(我的示例适用于x轴,但工作原理相同y轴):
There are at least two ways for achieving this in base graph (my examples are for the x-axis, but work the same for the y-axis):
-
使用
par(xaxp = c(x1, x2, n))
或plot(..., xaxp = c(x1, x2, n))
定义极限刻度线的位置(x1
&x2
)和刻度线之间的间隔数(n
).因此,n+1
是绘制的刻度线的数量. (这仅在不使用对数标度的情况下有效,有关具有对数标度的行为,请参见?par
.)
Use
par(xaxp = c(x1, x2, n))
orplot(..., xaxp = c(x1, x2, n))
to define the position (x1
&x2
) of the extreme tick marks and the number of intervals between the tick marks (n
). Accordingly,n+1
is the number of tick marks drawn. (This works only if you use no logarithmic scale, for the behavior with logarithmic scales see?par
.)
您可以完全隐藏轴的绘制,以后再使用axis()
添加刻度线.
要抑制轴的绘制,请使用plot(... , xaxt = "n")
.
然后用side
,at
和labels
调用axis()
:axis(side = 1, at = v1, labels = v2)
.在side
指向轴的侧面(1 = x轴,2 = y轴)的情况下,v1
是包含刻度线位置的矢量(例如,c(1, 3, 5)
,如果您的轴的范围是从0到6,您需要三个标记),以及v2
一个包含指定刻度线标签的向量(必须与v1
相同,例如,c("group a", "group b", "group c")
).参见?axis
和
You can suppress the drawing of the axis altogether and add the tick marks later with axis()
.
To suppress the drawing of the axis use plot(... , xaxt = "n")
.
Then call axis()
with side
, at
, and labels
: axis(side = 1, at = v1, labels = v2)
. With side
referring to the side of the axis (1 = x-axis, 2 = y-axis), v1
being a vector containing the position of the ticks (e.g., c(1, 3, 5)
if your axis ranges from 0 to 6 and you want three marks), and v2
a vector containing the labels for the specified tick marks (must be of same length as v1
, e.g., c("group a", "group b", "group c")
). See ?axis
and my updated answer to a post on stats.stackexchange for an example of this method.
这篇关于更改绘图轴上刻度线的间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!