Re: [R] Stacked Area chart

From: Christian Lasarczyk <lasarczyk_at_gmail.com>
Date: Wed 17 Aug 2005 - 06:02:55 EST

Maybe this is useful:

stackedPlot <- function(data, time=NULL, col=1:length(data), ...) {

  if (is.null(time))
    time <- 1:length(data[[1]]);   

  plot(0,0

       , xlim = range(time)
       , ylim = c(0,max(rowSums(data)))
       , t="n" 
       , ...
       );
  

  for (i in length(data):1) {

    # Die Summe bis zu aktuellen Spalte
    prep.data <- rowSums(data[1:i]);     

    # Das Polygon muss seinen ersten und letzten Punkt auf der Nulllinie haben     prep.y <- c(0

, prep.data
, 0

                )

    prep.x <- c(time[1]

, time
, time[length(time)]
) polygon(prep.x, prep.y , col=col[i] , border = NA );

  }
}

dogs <- runif(10)+ 1:10;
cats <- 11 - dogs;
birds <- 11 - cats;
population <- data.frame(dogs,cats,birds); stackedPlot(population);

Documentation is bad (as this function is for personal use) and you may want to normalize your data, but it should be useful for different sized data.frames.

Best regards,

     Christian

2005/8/16, Mike Saunders <mike_saunders@umenfa.maine.edu>:

> I wish to do a stacked area chart to show how relative proportions of species within a stand have changed over time.
> 
> I know this is simple, but can someone point me to the right function (if it exists).  I have not had any luck finding it in the R-help, but maybe I am searching using the wrong keywords.
> 
> Thanks,
> Mike
> 
> 
> Mike Saunders
> Research Assistant
> Forest Ecosystem Research Program
> Department of Forest Ecosystem Sciences
> University of Maine
> Orono, ME  04469
> 207-581-2763 (O)
> 207-581-4257 (F)
> 
>         [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Aug 17 06:10:50 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:24:25 EST