Statistics
| Revision:

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

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
} else {
24
        println "Selection is not an Index. Aborting."
25
        return
26
}
27

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

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

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