在R中延长绘图轴的长度?

时间:2022-05-24 14:59:41

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

如何在R中扩展轴线以覆盖数据范围?例如,在

在R中延长绘图轴的长度?

my data goes to about 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?

我的数据大约到2100年,我希望x轴的线走得那么远,但是不要在2100处做一个刻度线或标签。这在R中是否可能?

Here is the code used to make the above plot:

以下是用于制作上述情节的代码:

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

Thanks.

谢谢。

3 个解决方案

#1


8  

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)

在R中延长绘图轴的长度?

#2


3  

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

使用hist(),您可以使用轴控制刻度和标签的位置:

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:

如果要查看标记的每200个间隔,可以使用las参数旋转标签:

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

#3


2  

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)

从帮助开始(轴)

#1


8  

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)

在R中延长绘图轴的长度?

#2


3  

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

使用hist(),您可以使用轴控制刻度和标签的位置:

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:

如果要查看标记的每200个间隔,可以使用las参数旋转标签:

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

#3


2  

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)

从帮助开始(轴)