[rkward-cvs] SF.net SVN: rkward: [1651] trunk/rkward/rkward/plugins/plots

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Mar 20 00:00:30 UTC 2007


Revision: 1651
          http://svn.sourceforge.net/rkward/?rev=1651&view=rev
Author:   tfry
Date:     2007-03-19 17:00:29 -0700 (Mon, 19 Mar 2007)

Log Message:
-----------
Update density plot:
* adjustments to local()
* plot only either regular density plot, or highest density regions plot. Both at once should rarely be useful
* remove the 'no estimation' option. It is not useful in this context
* properly enable/disable elements according to whether they are needed
* some layout adjustments
* assorted small fixes

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/plots/density_plot.php
    trunk/rkward/rkward/plugins/plots/density_plot.xml

Modified: trunk/rkward/rkward/plugins/plots/density_plot.php
===================================================================
--- trunk/rkward/rkward/plugins/plots/density_plot.php	2007-03-19 22:57:52 UTC (rev 1650)
+++ trunk/rkward/rkward/plugins/plots/density_plot.php	2007-03-20 00:00:29 UTC (rev 1651)
@@ -1,55 +1,60 @@
 <?
-	function preprocess () {
-	}
-	
-	function calculate () {
-	}
-	
-	function printout () {
-	$giveRkern = getRK_val ("giveRkern");
+function preprocess () {
+	global $dodensity_plot;
+	$dodensity_plot = (getRK_val ("plot_type") == "density_plot");
+
+	if (!$dodensity_plot) { ?>
+require(hdrcde)
+<?	}
+}
+
+function calculate () {
+}
+
+function preview () {
+	preprocess ();
+	calculate ();
+	doPrintout (false);
+}
+
+function printout () {
+	doPrintout (true);
+}
+
+function doPrintout ($final) {
+	global $dodensity_plot;
 	$adjust = getRK_val ("adjust");
-	$bw = getRK_val ("bw");
 	$x = getRK_val ("x");
+	$resolution = getRK_val ("n");
 	$narm = getRK_val ("narm");
-	$kern = "c(\"" . getRK_val ("kern") . "\")";
-	$dodensity_plot = getRK_val ("dodensity_plot");
-	$dohdrcde_plot = getRK_val ("dohdrcde_plot");
-	$dorug_density = getRK_val ("rug_density");
-	$dorug_hdrcde = getRK_val ("rug_hdrcde");
+	$kern = getRK_val ("kern");
+	if ($kern == "gaussian") {
+		$bw = getRK_val ("bw");
+	}
+	$dorug = getRK_val ("rug");
 
-	if ($dodensity_plot) { ?>
-rk.header ("Density Plot", list ("Variable", rk.get.description (<? echo ($x); ?>), "Band Width", c("<? getRK ("bw"); ?>"), "Estimate Density", <? echo ($giveRkern) ?>, "Adjust", <? echo ($adjust) ?>, "Remove Missing Values", <? echo ($narm) ?>, "Length", length (<? echo ($x); ?>), "n", <? getRK ("n"); ?>, "Smoothing Kernel", <? echo ($kern); ?>))
-<?	}
-	if ($dohdrcde_plot) { ?>
+	if ($final) {
+		if ($dodensity_plot) { ?>
+rk.header ("Density Plot", list ("Variable", rk.get.description (<? echo ($x); ?>)<? if (!empty ($bw)) { ?>, "Band Width", "<? echo ($bw); ?>"<? } ?>, "Adjust", <? echo ($adjust) ?>, "Remove Missing Values", <? echo ($narm) ?>, "Length", length (<? echo ($x); ?>), "Resolution", <? echo ($resolution); ?>, "Smoothing Kernel", "<? echo ($kern); ?>"))
+<?		} else { ?>
 rk.header ("Highest density regions", list ("Variable", rk.get.description (<? echo ($x); ?>)))
-<?	} ?>	
+<?		} ?>
 
 rk.graph.on ()
+<?	}
+		?>
 try ({
-<?	if ($dohdrcde_plot && $dodensity_plot) { ?>
-	par(mfrow=c(1,2))
-<?	} ?>
-
 <?	if ($dodensity_plot) { ?>
-	plot (density(<? echo ($x); ?>, bw = "<? echo ($bw); ?>", adjust = <? echo ($adjust); ?>, <? echo ($giveRkern); ?>, kern = <? echo ($kern); ?>, n = <? getRK ("n"); ?>, <? echo ($narm); ?><? getRK ("plotoptions.code.printout"); ?>))
-<?	} ?>
-
-<?	if ($dorug_density) { ?>
-	rug(<? echo ($x); ?>, <? getRK ("ticksize"); ?>, <? getRK ("lwd"); ?>, <? getRK ("side"); ?>, col ="<? getRK ("col_rug"); ?>")
-<?	}
-
-	if ($dohdrcde_plot) { ?>
-	require(hdrcde)
+	plot (density(<? echo ($x); if (!empty ($bw)) echo (", bw=\"" . $bw . "\""); ?>, adjust = <? echo ($adjust); ?>, kern = "<? echo ($kern); ?>", n = <? echo ($resolution); ?>, <? echo ($narm); ?>)<? getRK ("plotoptions.code.printout"); ?>)
+<?	} else { ?>
 	hdr.den(<? echo ($x); ?><? getRK ("plotoptions.code.printout"); ?>)
 <?	}
-	if ($dorug_hdrcde) { ?>
-	rug(<? echo ($x); ?>, <? getRK ("ticksize"); ?>, <? getRK ("lwd"); ?>, <? getRK ("side"); ?>, col ="<? getRK ("col_rug"); ?>")
-	<? } ?>
+	if ($dorug) { ?>
+	rug(<? echo ($x); ?>, <? getRK ("rug_ticksize"); ?>, <? getRK ("rug_lwd"); ?>, <? getRK ("rug_side"); ?><? getRK ("rug_col.code.printout"); ?>)
+<?	} ?>
 })
+<?	if ($final) { ?>
 rk.graph.off ()
-<?
-	}
-	
-	function cleanup () {
-	}
+<?	}
+}
 ?>

Modified: trunk/rkward/rkward/plugins/plots/density_plot.xml
===================================================================
--- trunk/rkward/rkward/plugins/plots/density_plot.xml	2007-03-19 22:57:52 UTC (rev 1650)
+++ trunk/rkward/rkward/plugins/plots/density_plot.xml	2007-03-20 00:00:29 UTC (rev 1651)
@@ -5,67 +5,82 @@
 		<connect client="plotoptions.xvar" governor="x.available"/>
 		<set id="plotoptions.allow_log" to="false"/>
 		<set id="plotoptions.allow_type" to="false"/>
+
+		<convert id="regular_density_plot" mode="equals" sources="plot_type.string" standard="density_plot"/>
+		<connect client="kern.enabled" governor="regular_density_plot"/>
+		<convert id="gaussian_kernel" mode="equals" sources="kern.string" standard="gaussian"/>
+		<convert id="bw_type_enabled" mode="and" sources="kern.enabled;gaussian_kernel"/>
+		<connect client="bw.enabled" governor="bw_type_enabled"/>
+		<connect client="adjust.enabled" governor="regular_density_plot"/>
+		<connect client="narm.enabled" governor="regular_density_plot"/>
+		<connect client="n.enabled" governor="regular_density_plot"/>
+
+		<connect client="rug_ticksize.enabled" governor="rug.state"/>
+		<connect client="rug_lwd.enabled" governor="rug.state"/>
+		<connect client="rug_side.enabled" governor="rug.state"/>
+		<connect client="rug_col.enabled" governor="rug.state"/>
 	</logic>
 	<dialog label="Density Plot" >
 		<tabbook>
 			<tab label="Variable(s)" >
 				<row>
 					<varselector id="vars" />
-					<varslot multi="false" type="numeric" id="x" source="vars" label="variable(s):" required="true" />
+					<column>
+						<varslot multi="false" type="numeric" id="x" source="vars" label="variable(s):" required="true" />
+						<stretch/>
+						<preview id="preview"/>
+					</column>
 				</row>
 			</tab>
 			<tab label="Options" >
 				<row>
 					<column>
-						<checkbox value_unchecked="0" value="1" checked="true" id="dodensity_plot" label="Highest density regions" />
-						<checkbox value_unchecked="0" value="1" checked="false" id="dohdrcde_plot" label="Highest density regions" />
-						<dropdown id="bw" label="Bandwidth">
-							<option value="nrd0" label="nrd0"/>
-							<option value="nrd" label="nrd"/>
-							<option value="ucv" label="ucv"/>
-							<option value="bcv" label="bcv"/>
-							<option value="SJ-ste" label="SJ-ste"/>
-							<option value="SJ-dpi" label="SJ-dpi"/>
-						</dropdown>
-						<spinbox type="real" id="adjust" label="Adjust Bandwidth" initial="1"/>
-					</column>
-					<column>
-						<radio id="narm" label="Remove Missing Values">
-							<option value="na.rm = TRUE" label="TRUE"/>
-							<option value="na.rm = FALSE" label="FALSE"/>
+						<radio id="plot_type" label="type of plot">
+							<option value="density_plot" checked="true" label="plot normal density"/>
+							<option value="hdr_plot" label="plot highest density regions"/>
 						</radio>
-						<column>
+						<frame id="normal_density_opts" label="density estimation options">
 							<row>
-								<radio id="giveRkern" label="Estimate Density">
-									<option value="give.Rkern = FALSE" label="Density estimated"/>
-									<option value="give.Rkern = TRUE" label="Density not estimated"/>
-								</radio>						
-								<spinbox id="n" initial="512" label="n" />
+								<column>
+									<dropdown id="kern" label="Smoothing Kernel">
+										<option value="gaussian" label="gaussian (default)"/>
+										<option value="rectangular" label="rectangular"/>
+										<option value="triangular" label="triangular"/>
+										<option value="epanechnikov" label="epanechnikov"/>
+										<option value="biweight" label="biweight"/>
+										<option value="cosine" label="cosine"/>
+										<option value="optcosine" label="optcosine"/>
+									</dropdown>
+									<dropdown id="bw" label="Bandwidth">
+										<option value="nrd0" label="nrd0"/>
+										<option value="nrd" label="nrd"/>
+										<option value="ucv" label="ucv"/>
+										<option value="bcv" label="bcv"/>
+										<option value="SJ-ste" label="SJ-ste"/>
+										<option value="SJ-dpi" label="SJ-dpi"/>
+									</dropdown>
+									<spinbox type="real" id="adjust" label="Adjust Bandwidth" initial="1"/>
+									<stretch/>
+								</column>
+								<column>
+									<checkbox id="narm" label="Remove Missing Values" value="na.rm=TRUE" value_unchecked="na.rm=FALSE" checked="true"/>
+									<spinbox id="n" initial="512" label="Resolution" />
+									<stretch/>
+								</column>
 							</row>
-							<stretch/>
-						</column>
-						<dropdown id="kern" label="Smoothing Kernel">
-							<option value="gaussian" label="gaussian (default)"/>
-							<option value="rectangular" label="rectangular"/>
-							<option value="triangular" label="triangular"/>
-							<option value="epanechnikov" label="epanechnikov"/>
-							<option value="biweight" label="biweight"/>
-							<option value="cosine" label="cosine"/>
-							<option value="optcosine" label="optcosine"/>
-						</dropdown>
-					<stretch/>
+						</frame>
 					</column>
 					<column>
 						<frame label="Rug">
-							<checkbox value_unchecked="0" value="1" checked="false" id="rug_density" label="Rug Density" />
-							<checkbox value_unchecked="0" value="1" checked="false" id="rug_hdrcde" label="Rug Highest density regions" />
-							<spinbox initial="0.03" id="ticksize" label="Ticksize" />
-							<spinbox initial="0.5" id="lwd" label="Line width of ticks" />
-							<radio label="Side of Rug" id="side">
+							<checkbox value_unchecked="0" value="1" checked="false" id="rug" label="Add rug" />
+							<spinbox initial="0.03" id="rug_ticksize" label="Ticksize" />
+							<spinbox initial="0.5" id="rug_lwd" label="Line width of ticks" />
+							<radio label="Side of Rug" id="rug_side">
 								<option value="side = 1" label="Rug on Bottom" />
 								<option value="side = 3" label="Rug on Top" />
 							</radio>
-							<input id="col_rug" initial="black" label="Color of ticks"/>
+							<embed id="rug_col" component="rkward::color_chooser" label="Color"/>
+							<stretch/>
 						</frame>
 					</column>
 				</row>


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