Jonathan Williams wrote:> I am having difficulty making R plot only integer labels on the x-axis > of a simple graph. I want to plot the median values of a score on each > of three occasions. Non-integer occasions are impossible. But, R keeps > labelling the x-axis with half-occasions, despite my attempts to stop > this using the "xaxs" and "xaxp" parameters of 'plot'. > > p1=c(1,2,3); p2=c(5,15,25) > plot(p1,p2,xlab='Occasion', ylab='Score', xlim=c(1,3), ylim=c(0,30), > xaxp=c(1,3,3), xaxs='r') > > Could someone let me know how to suppress the non-integer labels?How about this instead? plot(p1, p2, xlab='Occasion', ylab='Score', xlim=c(1,3), ylim=c(0,30), xaxt="n") axis(side=1, at=1:3, 1:3) -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
Jonathan Williams
2004-Feb-19 13:20 UTC
[R] suppressing non-integer labels for plot x-axis
Dear R-helpers, I am having difficulty making R plot only integer labels on the x-axis of a simple graph. I want to plot the median values of a score on each of three occasions. Non-integer occasions are impossible. But, R keeps labelling the x-axis with half-occasions, despite my attempts to stop this using the "xaxs" and "xaxp" parameters of 'plot'. p1=c(1,2,3); p2=c(5,15,25) plot(p1,p2,xlab='Occasion', ylab='Score', xlim=c(1,3), ylim=c(0,30), xaxp=c(1,3,3), xaxs='r') Could someone let me know how to suppress the non-integer labels? Thanks Jonathan Williams OPTIMA Radcliffe Infirmary Woodstock Road OXFORD OX2 6HE Tel +1865 (2)24356
Jonathan Williams wrote:> Dear R-helpers, > I am having difficulty making R plot only integer labels on the x-axis > of a simple graph. I want to plot the median values of a score on each > of three occasions. Non-integer occasions are impossible. But, R keeps > labelling the x-axis with half-occasions, despite my attempts to stop > this using the "xaxs" and "xaxp" parameters of 'plot'. > > p1=c(1,2,3); p2=c(5,15,25) > plot(p1,p2,xlab='Occasion', ylab='Score', xlim=c(1,3), ylim=c(0,30), > xaxp=c(1,3,3), xaxs='r') > > Could someone let me know how to suppress the non-integer labels?In this case supress the drawing of the x-axis and specify it explicitly, see ?axis: plot(p1, p2, xlab='Occasion', ylab='Score', xlim=c(1,3), ylim=c(0,30), xaxt="n") axis(1, at=1:3) Uwe Ligges
On Thu, 2004-02-19 at 07:20, Jonathan Williams wrote:> Dear R-helpers, > I am having difficulty making R plot only integer labels on the x-axis > of a simple graph. I want to plot the median values of a score on each > of three occasions. Non-integer occasions are impossible. But, R keeps > labelling the x-axis with half-occasions, despite my attempts to stop > this using the "xaxs" and "xaxp" parameters of 'plot'. > > p1=c(1,2,3); p2=c(5,15,25) > plot(p1,p2,xlab='Occasion', ylab='Score', xlim=c(1,3), ylim=c(0,30), > xaxp=c(1,3,3), xaxs='r') > > Could someone let me know how to suppress the non-integer labels?If you want finer control over the axis labeling, it is generally best to suppress the axis or axes in question and explicitly draw the axis using the axis() function. By default, the tick marks and labels will be the result of using the pretty() function, based upon the range of values you provide. Thus you get:> pretty(1:3)[1] 1.0 1.5 2.0 2.5 3.0 To avoid this and have more control, do something like: p1=c(1, 2, 3) p2=c(5, 15, 25) # Use 'xaxt = "n"' to suppress the x axis plot(p1, p2, xlab = 'Occasion', ylab = 'Score', xlim = c(1, 3), ylim = c(0, 30), xaxt = "n") # Now call axis to draw tick marks and labels at 1:3 axis(1, at = 1:3) See ?pretty, ?plot.default and ?axis for more information. HTH, Marc Schartz