[rkward-cvs] rkward/rkward/plugins/02plots/scatterplot code.php,NONE,1.1 description.xml,NONE,1.1

adrien adhardemare at users.sourceforge.net
Fri Apr 15 07:45:12 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/plugins/02plots/scatterplot
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11057/rkward/plugins/02plots/scatterplot

Added Files:
	code.php description.xml 
Log Message:
interface to the plot function

--- NEW FILE: description.xml ---
<!DOCTYPE rkplugin>
<document>
  <entry type="entry" id="scatterplot" label="Scatterplot" />
<!--Adrien d'Hardemare	
first attempt to produce simple plot using the plot function
A duplicate option has to be tested-->  <dialog>
    <tabbook>
      <tab label="Variables" >
        <row>
          <varselector id="vars" />
          <varslot multi="true" duplicate="true" classes="integer numeric" id="x" source="vars" label="'X' variables" required="true" />
          <varslot multi="true" duplicate="true" duplicate="true" classes="integer numeric" id="y" source="vars" label="'Y' variables" required="true" />
        </row>
      </tab>
      <tab label="Axes" >
        <row>
          <column>
            <radio id="columns" label="Value for 'X' scale" >
              <option value="FALSE" label="Default" />
              <option value="custoCol" label="Customize" />
            </radio>
            <varslot multi="false" classes="integer numeric" source="varname" id="Xscale" depend="custoCol" />
            <radio id="rows" label="Value for 'Y' scale" >
              <option value="FALSE" id="temp2" label="Default" />
              <option value="custoRow" label="Customize" />
            </radio>
            <varslot multi="false" classes="integer numeric " id="Yscale" source="varname" depend="custoRow" />
          </column>
          <varselector id="varname" />
        </row>
      </tab>
      <tab label="Type" >
        <radio id="type" label="Type of graphics" >
          <option value="'p'" label="Plot individual points " />
          <option value="'l'" label="Plot lines " />
          <option value="b" label="Plot points connected by lines (both)" />
          <option value="1" label="Plot points overlaid by lines " />
          <option value="'h'" label="Plot vertical lines from points to the zero axis (high-density)" />
          <option value="'s'" label="Step-function plots : the top of the vertical defines the point" />
          <option value="'S'" label="Step-function plots : the bottom of the vertical defines the point" />
          <option value="custoType" label="Customize" />
        </radio>
        <input size="medium" id="typeCusto" depend="custoType" label="Give a character vector eg : c('p','l')" />
      </tab>
      <tab label="Names" >
        <row>
          <column>
            <checkbox checked="false" value="1" id="isXaxis" label="Give a name to 'X' axis" />
            <input size="medium" id="Xname" initial="X" depend="isXaxis" label="Name for X axis" />
            <checkbox checked="false" value="1" id="isYaxis" label="Give a name to Y axis" />
            <input size="medium" id="Yname" initial="Y" label="Name of Y axis" depend="isYaxis" />
            <checkbox checked="false" value="1" id="isTitle" label="Give a title" />
            <input size="medium" id="main" depend="isTitle" />
            <checkbox checked="false" value="1" id="isSub" label="Give a subtitle" />
            <input size="medium" id="sub" depend="isSub" />
          </column>
          <column>
            <checkbox value_unchecked="FALSE" checked="true" value="TRUE" id="axes" label="Generate axes" />
            <checkbox value_unchecked="" checked="false" value="x" id="logX" label="X as logarythm" />
            <checkbox value_unchecked="" checked="false" value="y" id="logY" label="Y as logarythm" />
          </column>
        </row>
      </tab>
      <tab label="Options" >
        <frame>
          <row>
            <radio id="color" label="Color" >
              <option value="all" label="Same color for all variables" />
              <option value="each" label="Different for each variable" />
            </radio>
            <column>
              <text>
	  Enter value - for diff.col. enter a vector -
	  eg:  c(1,2) or c('red','green')
	  </text>
              <input size="small" id="col" initial="'black'" label=" " />
            </column>
          </row>
        </frame>
        <frame>
          <row>
            <radio id="isCe" label="Size" >
              <option value="all" label="Same for all variables" />
              <option value="each" label="Different for each variable" />
            </radio>
            <column>
              <text>
	  A numerical value giving the amount by which plotting text and symbols should be scaled relative to the default. 
	  </text>
              <input size="small" id="cex" initial="1" label="Enter value - for diff.size. enter a vector -" />
            </column>
          </row>
        </frame>
        <frame>
          <row>
            <radio id="isPch" label="Symbol" >
              <option value="all" label="Same for all variables" />
              <option value="each" label="Different for each variable" />
            </radio>
            <column>
              <text>
	  Either an integer specifying a symbol or a single character to be used as the default in plotting points.
	  </text>
              <input size="small" id="pch" initial="1" label="Enter value - for diff.symbol. enter a vector -" />
            </column>
          </row>
        </frame>
      </tab>
      <tab label="More options" >
        <text>
        Everything cannot be here handled : R is too flexibel as concerns plots. Nonetheless, you can add extra code before and after the code of the plugin if you want to add whatever. This will allow you to modify if you want before par() and after to add low-level graphs. Please refer to 'R : an introduction' 
     </text>
        <frame label="Advanced options" >
	<!-- doesn't work very well TODO
          <checkbox value_unchecked=" " checked="true" value="rk.graph.on()" id="rkgraphson" label="Enter 'rk.graph.on()'" />
	  -->
          <input size="big" id="before" label="Before plot" />
          <checkbox value_unchecked=" " checked="true" value="rk.graph.off()" id="rkgraphsoff" label="Enter 'rk.graph.off()'" />
          <!-- doesn't work very well TODO
	  <input size="big" id="after" label="After plot" />
	  -->
        </frame>
      </tab>
    </tabbook>
  </dialog>
  <wizard>
<!--variable
-->    <page>
      <row>
        <varselector id="vars" />
        <varslot multi="true" duplicate="true" classes="numeric integer" id="x" source="vars" label="'X' variables" required="true" />
        <varslot multi="true" duplicate="true" duplicate="true" classes="numeric integer" id="y" source="vars" label="'Y' variables" required="true" />
      </row>
    </page>
<!-- axes-->    <page>
      <row>
        <column>
          <radio id="columns" label="Value for 'X' scale" >
            <option value="FALSE" label="Default" />
            <option value="custoCol" label="Customize" />
          </radio>
          <varslot multi="false" classes="integer numeric" source="varname" id="Xscale" depend="custoCol" />
          <radio id="rows" label="Value for 'Y' scale" >
            <option value="FALSE" id="temp2" label="Default" />
            <option value="custoRow" label="Customize" />
          </radio>
          <varslot multi="false" classes="integer numeric " id="Yscale" source="varname" depend="custoRow" />
        </column>
        <varselector id="varname" />
      </row>
    </page>
<!--couleur
-->    <page>
      <frame>
        <row>
          <radio id="color" label="Color" >
            <option value="all" label="Same color for all variables" />
            <option value="each" label="Different for each variable" />
          </radio>
          <column>
            <text>
	  Enter value - for diff.col. enter a vector -
	  eg:  c(1,2) or c('red','green')
	  </text>
            <input size="small" id="col" initial="'black'" label=" " />
          </column>
        </row>
      </frame>
      <frame>
        <row>
          <radio id="isCex" label="Size" >
            <option value="all" label="Same for all variables" />
            <option value="each" label="Different for each variable" />
          </radio>
          <column>
            <text>
	  A numerical value giving the amount by which plotting text and symbols should be scaled relative to the default. 
	  </text>
            <input size="small" id="cex" initial="1" label="Enter value - for diff.size. enter a vector -" />
          </column>
        </row>
      </frame>
      <frame>
        <row>
          <radio id="isPch" label="Symbol" >
            <option value="all" label="Same for all variables" />
            <option value="each" label="Different for each variable" />
          </radio>
          <column>
            <text>
	  Either an integer specifying a symbol or a single character to be used as the default in plotting points.
	  </text>
            <input size="small" id="pch" initial="1" label="Enter value - for diff.symbol. enter a vector -" />
          </column>
        </row>
      </frame>
    </page>
<!--type
-->    <page>
      <radio id="type" label="Type of graphics" >
        <option value="'p'" label="Plot individual points " />
        <option value="'l'" label="Plot lines " />
        <option value="b" label="Plot points connected by lines (both)" />
        <option value="1" label="Plot points overlaid by lines " />
        <option value="'h'" label="Plot vertical lines from points to the zero axis (high-density)" />
        <option value="'s'" label="Step-function plots : the top of the vertical defines the point" />
        <option value="'S'" label="Step-function plots : the bottom of the vertical defines the point" />
        <option value="custoType" label="Customize" />
      </radio>
      <input size="medium" id="typeCusto" depend="custoType" label="Give a character vector eg : c('p','l')" />
    </page>
<!--titre-->    <page>
      <row>
        <column>
          <checkbox checked="false" value="1" id="isXaxis" label="Give a name to 'X' axis" />
          <input size="medium" id="Xname" initial="X" depend="isXaxis" label="Name for X axis" />
          <checkbox checked="false" value="1" id="isYaxis" label="Give a name to Y axis" />
          <input size="medium" id="Yname" initial="Y" label="Name of Y axis" depend="isYaxis" />
          <checkbox checked="false" value="1" id="isTitle" label="Give a title" />
          <input size="medium" id="main" depend="isTitle" />
          <checkbox checked="false" value="1" id="isSub" label="Give a subtitle" />
          <input size="medium" id="sub" depend="isSub" />
        </column>
        <column>
          <checkbox value_unchecked="FALSE" checked="true" value="TRUE" id="axes" label="Generate axes" />
          <checkbox value_unchecked="" checked="false" value="x" id="logX" label="X as logarythm" />
          <checkbox value_unchecked="" checked="false" value="y" id="logY" label="Y as logarythm" />
        </column>
      </row>
    </page>
<!-- avant apr?-->    <page>
      <text>
        Everything cannot be here handled : R is too flexibel as concerns plots. Nonetheless, you can add extra code before and after the code of the plugin if you want to add whatever. This will allow you to modify if you want before par() and after to add low-level graphs. Please refer to 'R : an introduction' 
     </text>
      <frame label="Advanced options" >
        <!-- doesn't work very well TODO
        <checkbox value_unchecked=" " checked="true" value="rk.graph.on()" id="rkgraphson" label="Enter 'rk.graph.on()'" />
	-->
        <input size="big" id="before" label="Before plot" />
	  <!-- doesn't work very well TODO
        <checkbox value_unchecked=" " checked="true" value="rk.graph.off()" id="rkgraphsoff" label="Enter 'rk.graph.off()'" />
	-->
        <input size="big" id="after" label="After plot" />
      </frame>
    </page>
  </wizard>
</document>

--- NEW FILE: code.php ---
<?
	function preprocess () {
	}
?>
<?

	function calculate () {
$x = str_replace ("\n", ",", trim (getRK_val ("x"))) ;
$y = str_replace ("\n", ",", trim (getRK_val ("y"))) ;

?>


<? #input ?>
rk.plugin.Xvar = list(<? echo ($x) ;?>) ; 
rk.plugin.Yvar = list(<? echo ($y) ;?>) ; 
rk.plugin.Xval =  c(<? echo ($x) ;?>) ;
rk.plugin.Yval =  c(<? echo ($y) ;?>) ;


<? # verification (chiant mais doit être fait)?>
rk.plugin.ok = TRUE ;
if (length(rk.plugin.Xvar) != length(rk.plugin.Yvar) ) { 
	rk.plugin.ok = FALSE ;
	stop("'X' is of length ",length(rk.plugin.Xvar)," and 'Y' of length ",length(rk.plugin.Yvar) )
	}
 if ( "<? getRK("color") ; ?>" == "each") {
	if (length( <? getRK('col') ; ?>) != length(rk.plugin.Xvar))
	{
		rk.plugin.ok = FALSE ;
		stop('only ', length( <? getRK('col') ; ?>) ,' color(s) is(are) displayed') ;
	}
}
if ( "<? getRK("isPch") ; ?>" == "each") {
	if (length( <? getRK('pch') ; ?>) != length(rk.plugin.Xvar))
	{
		rk.plugin.ok = FALSE ;
		stop('only ', length( <? getRK('pch') ; ?>) ,' symbol(s) is(are) displayed') ;
	}
}
if ( "<? getRK("isCex") ; ?>" == "each") {
	if (length( <? getRK('cex') ; ?>) != length(rk.plugin.Xvar))
	{
		rk.plugin.ok = FALSE ;
		stop('only ', length( <? getRK('pch') ; ?>) ,' size(s) is(are) displayed') ;
	}
}
if ( "<? getRK("type") ; ?>" == "custoType") {
	if (length( <? getRK('typeCusto') ; ?>) != length(rk.plugin.Xvar))
	{
		rk.plugin.ok = FALSE ;
		stop('only ', length( <? getRK('typeCusto') ; ?>) ,' type(s) is(are) displayed') ;
	}
}


if (rk.plugin.ok) {

<? #finding min and max for default plotin  ; ?>
<?  if (getRK_val("columns") == "custoCol" ) echo (getRK("Xscale") . "-> rk.plugin.Xval") ; ?> 
<?  if (getRK_val("rows") == "custoRow" ) echo (getRK("Yscale") . "-> rk.plugin.Yval") ; ?>
rk.plugin.Xdef = c(min(rk.plugin.Xval,na.rm=TRUE) , max(rk.plugin.Xval,na.rm=TRUE))
rk.plugin.Ydef = c(min(rk.plugin.Yval,na.rm=TRUE) , max(rk.plugin.Yval,na.rm=TRUE))

<? # names ?>
rk.plugin.Xname = '<? getRK("Xname") ?>' ;
rk.plugin.Yname = '<? getRK("Yname") ?>' ;
rk.plugin.title =  '<? getRK("main") ?>' ;
rk.plugin.sub =  '<? getRK("sub") ?>' ;
<? if  (getRK_val("isXaxis") != "1" ) echo ( "rk.plugin.Xname  = '' "  ) ?> 
<? if  (getRK_val("isYaxis") != "1" ) echo ( "rk.plugin.Yname  = '' "  ) ?> 
<? if  (getRK_val("isSub") != "1" ) echo ( "rk.plugin.sub  = '' "  ) ?> 
<? if  (getRK_val("isTitle") != "1" ) echo ( "rk.plugin.main  = '' "  ) ?> 


<? # type ?>
rk.plugin.tc = data.frame(
type = rep(NA,length(rk.plugin.Xvar)),
col = rep(NA,length(rk.plugin.Xvar)),
pch = rep(NA,length(rk.plugin.Xvar)),
cex = rep(NA,length(rk.plugin.Xvar)))

<? if  (getRK_val("type") != "custoType" ) echo ( getRK("type") . " ->  rk.plugin.tc[[1]]" ) ; 
else echo( getRK("typeCusto") . " ->  rk.plugin.type.tc[[1]]"  ) ?> 
rk.plugin.tc[[2]] = <? getRK("col")  ;?> 
rk.plugin.tc[[3]] = <? getRK("cex")  ;?> 
rk.plugin.tc[[4]] = <? getRK("pch")  ;?> 

<? # avant après ?>
<? /* TODO 
rk.plugin.on = expression( <? getRK("rkgraphson") ; ?>) ;
rk.plugin.off = expression( <? getRK("rkgraphsoff") ; ?>) ;
*/ ?>
rk.plugin.before = expression( <? getRK("before") ; ?>) ;
rk.plugin.after = expression( <? getRK("after") ; ?>) ;

<? # axes ?>
rk.plugin.axes = <? getRK("axes") ;?> 
rk.plugin.log = '<? getRK("logX") ; getRK("logY") ; ?>'


}
<?

	}

	?>
	<?

	function printout () {
	
?>
if (rk.plugin.ok) {

rk.graph.on()
# evaluating before
# doesn't work very well 
#if (!is.null(eval(rk.plugin.on))) eval(rk.plugin.on)
rk.graph.on()
if (!is.null(eval(rk.plugin.before))) eval(rk.plugin.before)

# making frame 
plot(rk.plugin.Xdef,rk.plugin.Ydef,type="n" , xlab = rk.plugin.Xname , ylab = rk.plugin.Yname , main = rk.plugin.title , sub = rk.plugin.sub , axes = rk.plugin.axes , log = rk.plugin.log)

# ploting 
for (rk.plugin.iterator in 1:length(rk.plugin.Xvar)) {
	points  (
		rk.plugin.Xvar[[rk.plugin.iterator]] ,
		rk.plugin.Yvar[[rk.plugin.iterator]] , 
		type = rk.plugin.tc[[1]][[rk.plugin.iterator]] , 
		col = rk.plugin.tc [[2]] [[rk.plugin.iterator]] ,
		cex = rk.plugin.tc [[3]] [[rk.plugin.iterator]] ,
		pch = rk.plugin.tc [[4]] [[rk.plugin.iterator]] 
		)
}

# evaluating after
if (!is.null(eval(rk.plugin.after))) eval(rk.plugin.after)
#doesn't work very well
#if (!is.null(eval(rk.plugin.off))) eval(rk.plugin.off)
rk.graph.off()
}

<?
	}
	
	function cleanup () {
?>

rk.plugin.remove = ls() [grep('rk.plugin',ls())]
rm(list=rk.plugin.remove)
rm(rk.plugin.remove)
 
<?
	}
?>





More information about the rkward-tracker mailing list