Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / r / Index2barplotMacro.groovy @ 736

History | View | Annotate | Download (1.1 kB)

1
package org.txm.macro.r;
2
// STANDARD DECLARATIONS
3

    
4
import org.kohsuke.args4j.*
5

    
6
import groovy.transform.Field
7

    
8
import org.txm.index.core.functions.Index
9
import org.txm.rcp.swt.widget.parameters.*
10
import org.txm.rcp.commands.*
11
import org.txm.Toolbox
12
import org.txm.statsengine.r.core.RWorkspace
13

    
14
def sel = corpusViewSelection
15

    
16
String symbol = null;
17
String prop = "none"
18
if (sel instanceof Index) {
19
        println "Sending Index data to R..."
20
        ((Index)sel).asRMatrix()
21
        symbol = "t("+((Index)sel).getSymbol()+'$data)'
22
        prop = ((Index)sel).getProperties().toString()
23
}
24

    
25
if (symbol == null) {
26
        println "Selection is not an Index. Aborting."
27
        return
28
}
29

    
30
def r = RWorkspace.getRWorkspaceInstance()
31
def file = File.createTempFile("IndexHist", ".svg", new File(Toolbox.getTXMHOMEPATH(), "results"))
32

    
33
/// BEGIN SCRIPTS
34
def script ="""
35
par(las=2)
36
barplot($symbol, xlab="$prop", ylab="f")
37
"""
38
/// END SCRIPTS
39
r.plot(file, script)
40
println "Result saved in: "+file.getAbsolutePath()
41

    
42
//display the graphic
43
monitor.syncExec(new Runnable() {
44
        @Override
45
        public void run() {        OpenSVGGraph.OpenSVGFile(file.getAbsolutePath(), "Distribution") }
46
});