How to get rid of the decimal digits on the x axis
I want to create a simple plot.
year=c(2005,2006,2007)
dat=c(1,2,3)
plot(year,dat)
How can I only show开发者_运维百科 the axis as the year without decimal digits? Thanks
Specify year
as a date, using as.Date
. Here is one way, using seq.Date
:
year=seq(as.Date("2005/01/01"), by="1 year", length.out=3)
dat=c(1,2,3)
plot(year,dat)
3 possible ways:
Control the label resolution with
xaxp
:plot(year,dat,xaxp=c(range(year),2))
Use a
Date
object for the x axis:year2 <- as.Date(paste(year,"-01-01",sep=""))
plot(year2,dat)
Construct the axis yourself:
plot(year,dat,xaxt="n")
axis(1,at=year)
精彩评论