3

I have several files that I need to plot but I noticed that with each plot Y axis is different(the values for all file are close to each other). I want the plot to display the values on y axis the same thing for all files.

example

if you plot f here you would get two ticks 100 and 300 only on y axis

f=c(1:477)

plot(f)

How can I tell R to display some thing like 100 200 300 400 not only 100 and 300 on Y axis

Julián Urbano
  • 8,378
  • 1
  • 30
  • 52
hyat
  • 1,047
  • 4
  • 15
  • 34
  • http://www.google.com.au/#output=search&sclient=psy-ab&q=r+plot+ticks&oq=r+plot+ticks&gs_l=hp.3..0l4.182.2650.0.2808.12.11.0.1.1.0.232.2072.0j4j6.10.0...0.0...1c.1.8.psy-ab.EbcB3lbdDTU&pbx=1&bav=on.2,or.r_qf.&bvm=bv.45107431,d.dGI&fp=2beda85718013896&biw=1362&bih=679 – sashkello Apr 11 '13 at 12:23
  • 3
    @sashkello, I completely agree that "Let me google that for you" is a sensible comment here, but it would be more useful/less snarky to spell it out, e.g. "try googling 'R plot ticks'" ... – Ben Bolker Apr 11 '13 at 12:28
  • http://stackoverflow.com/questions/3785089/r-change-the-spacing-of-tick-marks-on-the-axis-of-a-plot – Ben Bolker Apr 11 '13 at 12:28
  • sorry, but I feel like such questions is a waste of everyones' time. I mean, typing few keywords in google are so much quicker than typing all this stuff into the question in SO. – sashkello Apr 11 '13 at 12:31
  • 2
    you can (1) downvote for lack of research effort and/or (2) vote to close as duplicate ... – Ben Bolker Apr 11 '13 at 13:03

2 Answers2

16

When plotting, don't plot the y axis:

plot(x,y,yaxt="n")

And now plot the y axis, indicating the ticks:

ticks<-c(100,200,300,400)
axis(2,at=ticks,labels=ticks)

If you want to make sure that all plots show some range in the y axis (e.g. from 0 to 500), you can force it with ylim like this:

plot(x,y,yaxt="n",ylim=c(0,500))
Julián Urbano
  • 8,378
  • 1
  • 30
  • 52
1

Your problem is NOT in the parameter to use but just in the zoom of the R plot...

I just plotted

plot(1:477)

getting this

Plot with small zoom

and then just enlarging the plot

Plot with bigger zoom

Michele
  • 8,563
  • 6
  • 45
  • 72
  • Of course, you can programmatically turn this on and off with a variable `flag` with `yaxt=flag` BUT the trick is if you want to standard labels on, then set `flag <- "s"` and if you don't want the standard labels then use `flag <- "n"` (Adding this, because it took me a while to find "s") – Clem Wang Feb 15 '19 at 23:48