[Archetypes-commits] r28 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 11 11:23:16 CET 2010


Author: manuel
Date: 2010-03-11 11:23:15 +0100 (Thu, 11 Mar 2010)
New Revision: 28

Modified:
   pkg/R/archetypes-barplot.R
Log:
Make 'beside' argument more meaningful.

Modified: pkg/R/archetypes-barplot.R
===================================================================
--- pkg/R/archetypes-barplot.R	2010-02-25 14:27:36 UTC (rev 27)
+++ pkg/R/archetypes-barplot.R	2010-03-11 10:23:15 UTC (rev 28)
@@ -3,7 +3,8 @@
 #' Barplot of archetypes.
 #' @param height An \code{\link{archetypes}} object.
 #' @param data The original data matrix.
-#' @param beside Portray the archetypes as stacked bars.
+#' @param beside Show one barplot for each archetype, or one barplot
+#'    with stacked bars, either per archetype or per variable.
 #' @param percentage Show real values or percentages according to the
 #'    original data.
 #' @param ... Passed to the underlying \code{\link{barplot}} call.
@@ -11,8 +12,13 @@
 #' @method barplot archetypes
 #' @importFrom graphics barplot
 #' @export
-barplot.archetypes <- function(height, data, beside=TRUE, percentage=FALSE, ...) {
+barplot.archetypes <- function(height, data,
+                               beside=c('FALSE', 'atypes', 'variables'),
+                               percentage=FALSE, ...) {
+  beside <- match.arg(beside)
+
   atypes <- atypes(height)
+  rownames(atypes) <- sprintf('Archetype %s', seq(length = nrow(atypes)))
 
   if ( !percentage ) {
     ylab <- 'Value'
@@ -23,18 +29,21 @@
     atypes <- t(t(atypes) / m * 100)
     ylab <- 'Percentage'
     ylim <- c(0,100)
-  }  
+  }
 
-  if ( beside ) {
+  if ( beside == 'variables' ) {
     barplot(atypes, ylab=ylab, beside=TRUE, ylim=ylim, ...)
   }
+  else if ( beside == 'atypes' ) {
+    barplot(t(atypes), ylab=ylab, beside=TRUE, ylim=ylim, ...)
+  }
   else {
     p <- nrow(atypes)
-    
+
     par(mfrow=c(p,1))
-    for ( i in 1:p ) 
+    for ( i in 1:p )
       barplot(atypes[i,], main=paste('Archetype', i),
               ylab=ylab, ylim=ylim, ...)
-  }  
+  }
 }
 



More information about the Archetypes-commits mailing list