开发者

Extend the length of a plot axis in R?

How do you extend the axis line in R to cover the extent of your data? For example, in

Extend the length of a plot axis in R?

my data goes to about 开发者_JAVA技巧2100 and I would like the line for the x axis to go that far, but not make a tickmark or label at 2100. Is this even possible in R?

Here is the code used to make the above plot:

hist(x,breaks=50,xlab="...",main="",xlim=c(0,2100))

Thanks.


You need to use two axis commands; one for the axis line and another for the ticks and labels.

set.seed(2); x <- rlnorm(1000, log(130))
hist(x, breaks=seq(0, 3000, by=200), xlim=c(0,2100), xaxt="n")

axis(1, at=c(0,2100), labels=c("",""), lwd.ticks=0)
axis(1, at=seq(0 , 2000, by=200), lwd=0, lwd.ticks=1)

Extend the length of a plot axis in R?


As the famous quote

R> fortunes::fortune("yoda")

Evelyn Hall: I would like to know how (if) I can extract some of
the information from the summary of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
   -- Evelyn Hall and Simon 'Yoda' Blomberg
      R-help (April 2005)
R>

says "There is no if. Only how.".

You can set any axis labels you want by

  • suppressing the default axis labels and
  • setting the axis labels you want.

Start with help(axis)


With hist() you can control the location of the ticks and labels with axis:

hist( rlnorm(1000, log(130) ), breaks=seq(0, 3000, by=200), xlim=c(0,2100) , axes=FALSE)
axis(1, at=seq(0 , 2000, by=200) 

If you wanted to see every 200 interval labeled you can rotate the labels with the las argument:

axis(1, at=seq(0 , 2000, by=200) , las=2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜