0

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:

enter image description here

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

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Silvie
  • 9
  • 1
  • Hi, please provide some toy data next time, see: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jay.sf Jul 03 '22 at 20:30

1 Answers1

1

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

enter image description here


Data:

n <- 500
orientation <- data.frame(
  head_linear=sample(360, n, replace=TRUE),
  body_linear=sample(360, n, replace=TRUE)
)
jay.sf
  • 60,139
  • 8
  • 53
  • 110