Randomize Randomize - 2 months ago 16
R Question

Show right values on axis

I have this

Data.Frame
(
mydf
):

year total
1999 3967
2002 580
2005 5203
2008 2406


and to display it, I just run:

plot(mydf)


However I can see on the x-axis (
year
) the labels:

2000 2002 2004 2006 2008


How can I tell to
plot/axis
to display only the four expected values:
1999,2002,2005,2008
without trying to infer the sequence?

Answer

As akrun suggest, you can use:

plot(mydf, xaxt = "n")
axis(1, at = mydf$year)

Data:

mydf <- structure(list(year = c(1999L, 2002L, 2005L, 2008L), total = c(3967L, 
580L, 5203L, 2406L)), .Names = c("year", "total"), class = "data.frame",
row.names = c(NA, -4L))

enter image description here