I am an R novice trying to figure out plot(). Specifically, I am trying to plot the values of a numeric variable V for a set of years (1970, 1974, 1976, 1978, 1980). How do I get R to label the years I am plotting on the x-axis rather then some general levels (1970, 1975, 1980.) Using as.character(year) doesn't seem to help, and using as.factor(year) generates steps insteads of dots. Help will be most appreciated. I have listed the code I have been using below:> plot(y$year, y$V, type = "b") > plot(as.character(y$year), y$V, type = "b") > plot(as.character(y$year), y$V, type = "b")Thanks, NR
try text(c("1970", "1978", "1990"), x=1:3, y=1:3) after you first call plot(c(1, 3), c(1, 3), axes=F, type="n", xlab="", ylab="") to set the plotting area. Yuelin. -- From: Nirmala Ravishankar <n_ravishankar at yahoo.com> To: r-help at stat.math.ethz.ch Subject: [R] plot() Date: Mon, 6 Jan 2003 20:19:58 -0800 (PST) I am an R novice trying to figure out plot(). Specifically, I am trying to plot the values of a numeric variable V for a set of years (1970, 1974, 1976, 1978, 1980). How do I get R to label the years I am plotting on the x-axis rather then some general levels (1970, 1975, 1980.) Using as.character(year) doesn't seem to help, and using as.factor(year) generates steps insteads of dots. Help will be most appreciated. I have listed the code I have been using below: > plot(y$year, y$V, type = "b") > plot(as.character(y$year), y$V, type = "b") > plot(as.character(y$year), y$V, type = "b") Thanks, NR ______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
First, it is usual to make plots with generic scales rather than label each of the x values used, especially when they are irregularly spaced (as here). But if you want to do that, use axis() to create your own axis. Here's a test y <- data.frame(year=c(1970, 1974, 1976, 1978, 1980), V=rnorm(5)) attach(y) plot(year, V, type = "b", xaxt="n") axis(1, year, year) detach() On Mon, 6 Jan 2003, Nirmala Ravishankar wrote:> I am an R novice trying to figure out plot(). > Specifically, I am trying to plot the values of a > numeric variable V for a set of years (1970, 1974, > 1976, 1978, 1980). How do I get R to label the years > I am plotting on the x-axis rather then some general > levels (1970, 1975, 1980.) Using as.character(year) > doesn't seem to help, and using as.factor(year) > generates steps insteads of dots. > > Help will be most appreciated. I have listed the code > I have been using below: > > > plot(y$year, y$V, type = "b") > > plot(as.character(y$year), y$V, type = "b") > > plot(as.character(y$year), y$V, type = "b")-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595