Apologies, basic question on plot. y <- c(-4,3,-2,1); x <- c("time 1", "time 2", "time 3", "time 4"); plot(x,y, type="b"); of course fails. x <- 1:4 makes it succeed, but then I have too many ticks on my X axis. I want exactly 4 tickmarks. It would also be nicer if I could name the ticks. I looked at ?par and Venables&Ripley, and tried the lab and xaxp parameters. I could not figure out how to use them productively. could someone please let me know? help appreciated. /iaw
On Thu, 2004-01-22 at 12:32, ivo welch wrote:> Apologies, basic question on plot. > > y <- c(-4,3,-2,1); > x <- c("time 1", "time 2", "time 3", "time 4"); > plot(x,y, type="b"); > > of course fails. > x <- 1:4 > makes it succeed, but then I have too many ticks on my X axis. I want > exactly 4 tickmarks. It would also be nicer if I could name the ticks. > > I looked at ?par and Venables&Ripley, and tried the lab and xaxp > parameters. I could not figure out how to use them productively. could > someone please let me know? help appreciated. /iawUse 'xaxt' in the call to plot() and then use axis() to control the axis tick marks and labels: y <- c(-4, 3, -2, 1) x <- c(1:4) # Do not plot the x axis plot(x, y, type = "b", xaxt = "n") # Now draw the x axis with text labels axis(1, at = 1:4, labels = paste("Time", 1:4, sep = " ")) See ?par (xaxt) and ?axis for more information. You can also use: plot(x, y, axes = FALSE) and then use axis(1, ...) and axis(2, ...) if you want to control both the x and y axes, respectively. HTH, Marc Schwartz
On Thu, Jan 22, 2004 at 01:32:29PM -0500, ivo welch wrote:> > Apologies, basic question on plot. > > y <- c(-4,3,-2,1); > x <- c("time 1", "time 2", "time 3", "time 4"); > plot(x,y, type="b"); > > of course fails. > x <- 1:4 > makes it succeed, but then I have too many ticks on my X axis. I want > exactly 4 tickmarks. It would also be nicer if I could name the ticks. > > I looked at ?par and Venables&Ripley, and tried the lab and xaxp > parameters. I could not figure out how to use them productively. could > someone please let me know? help appreciated. /iawy <- c(-4,3,-2,1) xlab <- c("time 1", "time 2", "time 3", "time 4") x <-1:4 plot(x,y, type="b", axes=FALSE) axis(2) axis(1, at=x, labels=xlab) box() If you use 'axis(1, at=x)' you can do without xlab, but get only the bare numbers. box() is needed to frame the whole thing as the default axes=TRUE for plot() does. Gruss, Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page
You need to look at ?axis. Try this: y <- c(-4,3,-2,1) x <- c("time 1", "time 2", "time 3", "time 4") plot(seq(1,length(x), by = 1), y, type = "b", axes = FALSE, xlab "Times", ylab = "Stuff") axis(1, at = seq(1,length(x), by = 1), labels = x) axis(2) HTH, Andy