0
votes

The title is probably not the best way to express what I'm trying to do. I'm trying to plot data for each of 12 editions of a book, about every 5 years (but the last two are different intervals). I want it to plot the labeled edition years but it plots as 5-year intervals. Here's the data:

x <- c(1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 2000, 2004, 2008, 2014)
y1 <- c(43, 58, 75, 72, 76, 86, 102, 107, 112, 83, 82, 73)
y2 <- c(42, 63, 70, 74, 76, 77, 78, 78, 78, 78, 78, 78)
y3 <- c(10, 15, 17, 23, 27, 29, 34, 36, 37, 37, 37, 38)

plot(x, y1, ylim=c(0, 120), xlab="Edition", type = "b")
lines(x, y1)
lines(x, y3)

I tried this and it's almost there, but not every label is showing: plot(x, y1, ylim=c(0, 120), xlab="Edition", type = "b", xaxt='n') axis(1, at = c(1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 2000, 2004, 2008, 2014), labels= c("1960", "1965", "1970", "1975", "1980", "1985", "1990", "1995", "2000", "2004", "2008", "2014"))

1

1 Answers

2
votes

If you want to plot axis marks at very particular locations, you should take care of the drawing yourself. Here we turn off the default x axis and tell R where to draw marks explicitly.

plot(x, y1, ylim=c(0, 120), xlab="Edition", type = "b", xaxt="n")
axis(1, at=x)
#lines(x, y1)
lines(x, y3)

enter image description here