Hallo all
 
I realise this might be a "too much to ask" question, but can I improve the 
Lattice plot produced by the following code? The type of figure I would like to 
produce in each segment of the plot appears below the code.
 
library(reserving)  # http://toolkit.pbwiki.com/RToolkit 
<http://toolkit.pbwiki.com/RToolkit> 
data(GenIns)
GenInsInc <- incrementalTriangle(GenIns)
basicCL <- ChainLadder(GenIns, quarterly=FALSE, usetail=FALSE, YOA=c(1997:2006))
# lattice plot by underwriting years
plot(basicCL, byYOA=TRUE)
 
Instead of the ordinary "confidence bands" produced by the re lines, I would 
like to display a type of "funnel", as illustrated in the code below:
 
funnelGraph <- function(x, ylim, bands, ...)
{
  #----------------------------------------------------------------------
  # Function to plot a funnel graph
  # Requires package: RColorBrewer
  #
  # Created by Nigel De Silva, 3 June 2006
  # [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
  #----------------------------------------------------------------------
  require(RColorBrewer)
  # Determine confidence levels for graph
  if(missing(bands)) bands <- 40
  ci <- seq(from=0.50, to=0.995, length=bands)
  q <- c(0.5-ci/2, 0.5+ci/2)
  # Calculate points to plot
  central <- apply(x, 2, mean)
  areas <- apply(x, 2, quantile, q)
  time <- 1:dim(x)[2]
  # Set up plot
  if(missing(ylim))
    ylim = range(pretty(range(areas)))
  plot(time, central, ylim=ylim, type="n", ...)
  # Draw areas
  mypalette <- c(rev(brewer.pal(9, "Blues")), "White") #9 is max no of colours
  mypalette <- colorRampPalette(mypalette, space="Lab", bias=0.25)
  mypalette <- mypalette(bands)
  for(i in rev(1:length(ci))){
    x <- c(time, rev(time))
    y <- c(areas[i, ], rev(areas[i + length(ci), ]))
    polygon(x, y, col=mypalette[i], border=NA)
  }
  # Draw mean path
  lines(time, central, lwd=2, col=2)
  return(time)
}
library(MASS)
assets <- mvrnorm(10000, rep(0.05, 5), diag(rep(0.08, 5)))
assets <- exp(cbind(0, assets))
assets <- t(apply(assets, 1, cumprod))
funnelGraph(assets, xlab="Year", main="Projected Assets")
 
Thanks for any help!
Regards
Jacob
 
 
Jacob L van Wyk
Dept of Statistics
University of Johannesburg
P O Box 524
Auckland Park 2006
South Africa
Tel: +27-11-559-3080
Fax: +27-11-559-2499
Cell: +27-82-859-2031

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to