简体   繁体   English

如何更改基本直方图中 y 轴的刻度线?

[英]How to change tick-marks for y-axis in base histogram?

I would like to change my Y axis of these histograms to start at 20 and end at 180 AND making it so there is always 20 between each number (20, 40, 80,...).我想将这些直方图的 Y 轴更改为从 20 开始并以 180 结束,并使其在每个数字(20、40、80、...)之间始终存在 20。 How should I do it?我该怎么做?

I read about yaxis command, but I just dont know how to make it work as I am a total noob in coding (no education in that area).我阅读了有关 yaxis 命令的信息,但我只是不知道如何使它工作,因为我是编码方面的菜鸟(在该领域没有受过教育)。

This is the graph I am working on:这是我正在处理的图表:

在此处输入图像描述

And this is the code I have:这是我的代码:

 orientation$head_linear <- ifelse(orientation$head > 180, 360 - orientation$head, orientation$head) orientation$body_linear <- ifelse(orientation$body > 180, 360 - orientation$body, orientation$body) par(mfrow = c(2,1)) hist(orientation$head_linear, main = NULL, ylim=c(20,180), ylab = NULL, xlab = NULL) hist(orientation$body_linear, main = NULL, ylim=c(20, 180), ylab = NULL, xlab = " Odchylka od vletového otvoru ")

I have set the limit of Y axis with ylim code, but it doesnt seem to work (I have succesfully used it before in different work).我已经用 ylim 代码设置了 Y 轴的限制,但它似乎不起作用(我之前在不同的工作中成功使用过它)。

Maybe you mean the xaxt= argument whith which you can omit the y-axis.也许您的意思是xaxt=参数,您可以省略 y 轴。 If you use it, you may create a custom axis afterwards.如果你使用它,你可以在之后创建一个自定义axis Use a seq(from=0, to=360, by=20) for it's at= argument.使用seq(from=0, to=360, by=20)作为at=参数。

 par(mfrow=c(2, 1)) hist(orientation$head_linear, main=NULL, yaxt='n', ylab=NULL, xlab=NULL) axis(side=2, at=seq(from=0, to=360, by=20)) hist(orientation$body_linear, main=NULL, yaxt='n', ylab=NULL, xlab=" Odchylka od vletového otvoru ") axis(2, seq(0, 360, 20))

在此处输入图像描述


Data:数据:

 n <- 500 orientation <- data.frame( head_linear=sample(360, n, replace=TRUE), body_linear=sample(360, n, replace=TRUE) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM