[英]In R, how to set the breaks of x-axis?
Say here is my code: 说这是我的代码:
plot(data ylab="x", xlab="y", xlim=c(1, 13))
But the x-axis of the plot presented like this: 但是绘图的x轴显示如下:
As you see, the x-axis presented from 2 to 12 by 2. However, I want it shown from 1 to 13 by 1 step, how can I realize that? 如您所见,x轴从2到12乘2表示。但是,我希望从1到13乘1步显示x轴,我如何实现呢?
You've defined the limits for your axis; 您已经定义了轴的极限。 however, R is inserting the "default" values for it. 但是,R正在为其插入“默认”值。
To alter them, you need to 要更改它们,您需要
xaxt='n'
使用xaxt='n'
“覆盖”轴的创建 So, let's get it done! 所以,让我们完成它!
plot(data, ylab="x", xlab="y", xlim=c(1, 13), xaxt='n')
# Now, define a custom axis
axis(side = 1, at=1:13)
This will give you what you want. 这会给你你想要的。
From the documentation, axis()
: 从文档中, axis()
:
Description 描述
Adds an axis to the current plot, allowing the specification of the side, position, labels, and other options. 在当前图上添加一个轴,从而可以指定边,位置,标签和其他选项。
Usage 用法
axis(side, at = NULL, labels = TRUE, tick = TRUE, line = NA, pos = NA, outer = FALSE, font = NA, lty = "solid", lwd = 1, lwd.ticks = lwd, col = NULL, col.ticks = NULL, hadj = NA, padj = NA, ...)
Some of the most used arguments are: 一些最常用的参数是:
side
(integer) 1=below, 2=left, 3=above and 4=right. side
(整数)1 =下方,2 =左侧,3 =上方和4 =右侧。 at
(vector) position of the tick marks at
该刻度标记(矢量)的位置 labels
(vector) labels for the tick marks. 刻度线的labels
(矢量)标签。 The vector must be the same size of at
. 所述载体必须是相同的大小at
。 If ommited, the values of at
will be used. 如果省略,将使用at
的值。 FALSE
hides any labels FALSE
隐藏任何标签 Useful reference: 有用的参考资料:
Have a look at this code: http://cran.r-project.org/doc/contrib/Lemon-kickstart/axbreak.R 看看下面的代码: http : //cran.r-project.org/doc/contrib/Lemon-kickstart/axbreak.R
You have to source that file in order to use the function: 您必须提供该文件的源代码才能使用该功能:
source('http://cran.r-project.org/doc/contrib/Lemon-kickstart/axbreak.R')
axis.break(axis=1,breakpos,bgcol="white",breakcol="black", style=c("slash","zigzag"),brw=0.02)
Adapt to your liking. 适应您的喜好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.