[rkward-cvs] SF.net SVN: rkward: [1349] trunk/rkward/rkward/plugins/plots/barplot.php

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Feb 7 21:25:20 UTC 2007


Revision: 1349
          http://svn.sourceforge.net/rkward/?rev=1349&view=rev
Author:   tfry
Date:     2007-02-07 13:25:20 -0800 (Wed, 07 Feb 2007)

Log Message:
-----------
Deal better with vectors with attributes, vectors spanning below 0, and a bit of formatting

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/plots/barplot.php

Modified: trunk/rkward/rkward/plugins/plots/barplot.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/barplot.php	2007-02-07 19:59:25 UTC (rev 1348)
+++ trunk/rkward/rkward/plugins/plots/barplot.php	2007-02-07 21:25:20 UTC (rev 1349)
@@ -9,11 +9,10 @@
 	doPrintout (true);
 }
 	
-function cleanup () {
-	?>
+function cleanup () { ?>
 rm (list=grep ("^rk.temp", ls (), value=TRUE))
-	<?
-	}
+<?
+}
 	
 function preview () {
 	preprocess ();
@@ -23,11 +22,16 @@
 }
 	
 function doPrintout ($final) {
-	$vars = str_replace ("\n", ",", trim (getRK_val ("x"))) ; 
+	$vars = str_replace ("\n", ",", trim (getRK_val ("x"))) ;
+	$labels = (getRK_val ("labels")=="TRUE");
 ?>
-
 rk.temp.x <- (<? echo ($vars); ?>)
-if(is.factor(rk.temp.x)) rk.temp.x=summary(rk.temp.x)
+if(is.factor(rk.temp.x)) {
+	rk.temp.x <- summary(rk.temp.x)
+} else {
+	# barplot is a bit picky about attributes, so we need to convert to vector explicitely
+	if(!is.matrix(rk.temp.x)) rk.temp.x <- as.vector(rk.temp.x)
+}
 
 <? 
 	if ($final) { ?>
@@ -37,20 +41,20 @@
 <?	}
 ?>
 try ({
-	<?
-	if (getRK_val ("beside") == "TRUE") {
-	?>
-rk.temp.barplot <-barplot((rk.temp.x)<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(rk.temp.x)) dim(rk.temp.x) else length(rk.temp.x)) <? } ?>, beside=<? getRK ("beside"); ?>, legend.text=<? getRK ("legend"); ?>,  ylim = range(rk.temp.x) * c(0, 1.2))
-	<?
-	}
-	if ((getRK_val ("beside") == "TRUE") && getRK_val ("labels")=="TRUE") { 
-	?>
+<?	if (getRK_val ("beside") == "TRUE") { ?>
+<?		if ($labels) { ?>
+# adjust the range so that the labels will fit
+rk.temp.range <- range (rk.temp.x, na.rm=TRUE) * 1.2
+if (rk.temp.range[1] > 0) rk.temp.range[1] <- 0
+if (rk.temp.range[2] < 0) rk.temp.range[2] <- 0
+<?		} ?>
+rk.temp.barplot <- barplot((rk.temp.x)<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(rk.temp.x)) dim(rk.temp.x) else length(rk.temp.x)) <? } ?>, beside=<? getRK ("beside"); ?>, legend.text=<? getRK ("legend"); ?><? if ($labels) echo (", ylim = rk.temp.range"); ?>)
+<?		if ($labels) { ?>
 text(rk.temp.barplot, rk.temp.x, labels=rk.temp.x, pos=<? getRK ("place"); ?>, offset=.5)
-	<? } 
-	if (getRK_val ("beside") == "FALSE") { 
-	?> 
+<?		}
+	} else { ?>
 barplot((rk.temp.x)<? if (getRK_val ("rainbow")=="TRUE") { ?>, col=rainbow( if(is.matrix(rk.temp.x)) dim(rk.temp.x) else length(rk.temp.x)) <? } ?>, legend.text=<? getRK ("legend"); ?>)
-	<? } 
+<?	}
 	?>
 })
 <?	if ($final) { ?>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list