[R] plot()
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Tue Jan 7 08:54:03 CET 2003
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
More information about the R-help
mailing list