简体   繁体   中英

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,...). 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).

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).

Maybe you mean the xaxt= argument whith which you can omit the y-axis. If you use it, you may create a custom axis afterwards. Use a seq(from=0, to=360, by=20) for it's at= argument.

 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) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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