ヒストグラムのオプション
re.eval("hist(c,main='Histogram',col='#dcdcdc',xlab='range')");
main : タイトル、col : 色、xlab : x座標
R用の配列生成
StringBuffer buf = new StringBuffer();
buf.append("c<-c br=""> for(int i = 0; i < result.length; i++){
if(i == result.length -1)
buf.append(result[i]+")");
else
buf.append(result[i]+",");
}
String c_value = buf.toString();
re.eval("c<- c_value="" p="">
StringBufferを使いました。前に書いた(http://mizunolab.sist.ac.jp/2015/12/multiple-insertstringbuffer.html)を参考にしてます。
こんな感じで、MySQLクラスはそのまま。
[JRITest08.java]
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
import java.sql.*;
import java.util.Arrays;
public class JRITest08 {
public static void main(String[] args)
{
MySQL mysql = new MySQL();
Rengine re = new Rengine( new String[]{"--no-save"}, false, null );
ResultSet rs = mysql.selectOperators();
double result [] = new double[15];
double sum = 0;
int index = 0;
try {
while(rs.next()){
sum += rs.getDouble("awareness");
sum += rs.getDouble("decision");
sum += rs.getDouble("communication");
sum += rs.getDouble("leadership");
//result[index] = sum/48*100;
result[index] = sum;
sum = 0;
index ++;
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println(Arrays.toString(result));
StringBuffer buf = new StringBuffer();
buf.append("c<-c(");
for(int i = 0; i < result.length; i++){
if(i == result.length -1)
buf.append(result[i]+")");
else
buf.append(result[i]+",");
}
String c_value = buf.toString();
re.eval("c<-"+c_value);
REXP x = re.eval("summary(c)");
System.out.println(x);
double [] ary = x.asDoubleArray();
for (int i = 0; i < ary.length; i++) {
System.out.println(ary[i]);
}
re.eval("png('hist02.png', 640, 480)");
re.eval("hist(c,main='Frequency Distribution for NOTSS evaluation average of each operator',col='#dcdcdc',xlab='range')");
re.eval("dev.off()");
re.end();
}
}
[notss_analysis@ip-10-0-0-217 rjava]$ javac JRITest08.java
[notss_analysis@ip-10-0-0-217 rjava]$ java -Djava.library.path=/usr/lib64/R/library/rJava/jri/ JRITest08
[92.1875, 97.22222222222085, 90.70512820512708, 92.46794871795, 97.64492753623125, 88.5869565217375, 89.91228070175416, 87.73148148148331, 78.47222222222229, 76.33928571428582, 79.03225806451624, 62.05357142857145, 95.83333333333334, 70.83333333333334, 70.22058823529417, 61.111111111111036, 56.24999999999979]
[REAL* (56.25, 70.83, 87.73, 81.56, 92.19, 97.64)]
56.25
70.83
87.73
81.56
92.19
97.64
FTPでグラフを確認すると、下記になります。
参考
http://bio-info.biz/tips/r_histogram.html
http://stat.biopapyrus.net/graph/hist.html->-c>
0 件のコメント:
コメントを投稿