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]]
On Tue, 16 Aug 2005 12:03:01 -0400 Mike Saunders wrote:> I wish to do a stacked area chart to show how relative proportions of > species within a stand have changed over time.If you don't want to show the marginal distribution over time, then you can use barplot() on the table of relative frequencies (e.g., obtained by prop.table()). If you want to show the marginal distribution, you can use mosaicplot(). The functions doubledecker() and mosaic() in package vcd might also be helpful. Z> 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 at 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 >
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 at 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 at 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 >
At 16:03 16/08/05, Mike Saunders wrote:>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 at 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.htmlI recently did some graphs using xyplot in lattice where I had the data ordered by days, the groups argument and possibly by condition. I have slightly reduced the code for general use and re run it The process is to create a matrix of cumulative data (xy) and to make a filled polygon for each of the groups using the previous group value as the lower limit of the polygon. For the first group there has to be a dummy lower limit in these cases of zero ie rep(0,5) in the single panel graph in the rbind sequence Plotting of a group line is referred to as j+1 row due to the fact that there is a dummy line for the lower polygon of the first group The first script is for a single graph where there were the groups (codeno) were 4 species. The days were 1,2,4,6,9 and the y values (comp ) were percentages. All groupings and conditions are numeric for both datasets Any NAs were converted to 0s so as not to give error messages etc. The second script is for a conditioned graph of similar data but is generalised. The maximum y limit can cause problems in setting. In these cases I had a good idea of what they would be. For count data it would be necessary to first do a calculation to find it. # Single panel xyplot(comp ~ days, data = stackln, as.table = T, groups = codeno, subscripts = T, panel= function(x,y,subscripts,groups) { xy <- rbind(rep(0,5), apply(sapply(1:4, function(j) y[groups[subscripts]==j]),1,cumsum)) for(j in 1:4){ grid.polygon(x = c(c(1,2,4,6,9), rev(c(1,2,4,6,9)) ), y = c(xy[(j+1),],rev(xy[(j),]) ), gp = gpar(col = 0, fill = c(1,2,6,8)[j]), default.units = "native") } } ) # Conditioned panel xyplot(comp ~ days|grps3, data = in1, as.table = T, groups = codeno, subscripts = T, panel = function(x,y,subscripts,groups,panel.number) { grp.no <- sort(unique(groups[subscripts]) ) x.vals <- sort(unique(x)) xy <- rbind(rep(0,length(x.vals) ), apply(sapply(1:length(grp.no), function(j) y[groups[subscripts]==grp.no[j]]),1,cumsum)) for (j in 1:length(grp.no)) { grid.polygon(x = c(x.vals, rev(x.vals) ), y = c(xy[(j+1),], rev(xy[(j),]) ), gp = gpar(col = 0, fill = c(6,1,2,5,3,4,7,8)[j]), default.units = "native") } # for (j in 1:length(grp.no)) } # panel ) Regards Duncan Mackay (The other Duncan Mackay) Duncan Mackay Dept of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email: dmackay8 at pobox.une.edu.au