robjhyndman / demography

demography package for R
https://pkg.robjhyndman.com/demography
73 stars 25 forks source link

Add legends for rainbow graphs #25

Open robjhyndman opened 8 years ago

robjhyndman commented 8 years ago
library(demography)

niceleg <- function(n, ylim=c(-10, 2), poly.x=c(112, 114), 
        text.x=104, text.y, text.lab=floor(seq(1816, 2013, length=5)))
{
  col <- rainbow(1.25*n)
  y <- seq(ylim[1], ylim[2], length=2*n+1)
  for(i in 1:n)
    polygon(c(poly.x[1],poly.x[1],poly.x[2],poly.x[2]), c(y[2*i-1], y[2*i+1], y[2*i+1], y[2*i-1]), border=NA, col=col[i])
  if(missing(text.y))
    text.y <- seq(y[2], y[2*n], length=length(text.lab))
  text(text.x, text.y, text.lab)
}

plot(fr.mort, series="male", main="France, Tx mortalite, Homme")
niceleg(length(fr.mort$year))