[英]Controling xlim in plot
My example :我的例子:
x = c(1:15)
y = c(-4:10)
plot(x, y)
R gives xlim
automatically as : 2, 4, 6, ..., 14
R 自动给出xlim
为: 2, 4, 6, ..., 14
How can I change it for : 1, 2, 3,..., 15
我怎样才能改变它: 1, 2, 3,..., 15
I've tried :我试过了 :
my.limits = as.numeric(seq(1, 15, by = 1))
x = c(1:15)
y = c(-4:10)
plot(x, y, ylim = c(-4,10), xlim = my.limits)
But with error :但有错误:
Erreur dans plot.window(...) : valeur 'xlim' incorrecte
You can set the ticks manually like this:您可以像这样手动设置刻度:
x=c(1:15)
y=c(-4:10)
plot(x,y, xaxt="n", xlim = c(1,15))
axis(1, at = 1:15)
axt="n"
omits drawing a x-axis in plot
, first. axt="n"
省略在plot
绘制 x 轴。 axis
manually draws it afterwards - you got more control this way. axis
之后手动绘制它 - 这样您可以获得更多控制。
Adding to lukeA's answer and using the my.limits
sequence from your code:添加到 lukeA 的答案并使用代码中的my.limits
序列:
# Tick marks every 1 unit:
my.limits = as.numeric(seq(1, 15, by = 1))
x=c(1:15)
y=c(-4:10)
plot(x,y, xaxt="n", xlim = c(1,15))
axis(1, at = my.limits)
# Tick marks every 5 units:
my.limits = as.numeric(seq(0, 100, by = 5))
x=c(1:100)
y=c(-49:50)
plot(x,y, xaxt="n", xlim = c(1,100))
axis(1, at = my.limits)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.