n=100
c=2:5
data=sample(c ,n, replace = TRUE)
plot(c(0, n+1), c(-0.5, 1.5),type = "n",xaxs="i",yaxs="i",xlab="length",ylab="category",xaxt="n" )
xleft=seq(0,n,by=1)
xright=seq(1,n+1,by=1)
ybottom=rep(0,n)
ytop=rep(1,n)
rect(xleft, ybottom, xright, ytop,col=data)
legend(88, 1.45, legend=2:5, fill=c(col=2,col=3,col=4,col=5))