Maybe this is obvious, but is there a way to mix remote and interactive R calling, e.g. use the R console to source/format data and Rcaller to send plotting commands to the same console ? Thanks. Jerome
Hi guys, Rcaller is easy to use, but my problem is how do i save a heatmap generated with R in my local machine.
When i tried the following it returns nothing but an empty image :( <<---------------------------------------------------------------->> code.addRCode("postscript(filename = \"c:/h33.png\",width = 700, height = 700,units= \"px\", pointsize = 12,bg = \"white\", res = NA, family = \"\", restoreConsole = TRUE,type = c(\"windows\", \"cairo\", \"cairo-png\"))");
Here's some code that works - it's a JPanel, with button that launches the heatmap-generating code. It loads data from a .csv file and builds a heatmap from it. The .csv file is a "counts" file: there are 20 species listed in the first row, and in the second row was the number of animals of that species. Let me know if you can get it to work:
Maybe this is obvious, but is there a way to mix remote and interactive R calling, e.g. use the R console to source/format data and Rcaller to send plotting commands to the same console ?
ReplyDeleteThanks.
Jerome
Hi guys,
ReplyDeleteRcaller is easy to use, but my problem is how do i save a heatmap generated with R in my local machine.
When i tried the following it returns nothing but an empty image :(
<<---------------------------------------------------------------->>
code.addRCode("postscript(filename = \"c:/h33.png\",width = 700, height = 700,units= \"px\", pointsize = 12,bg = \"white\", res = NA, family = \"\", restoreConsole = TRUE,type = c(\"windows\", \"cairo\", \"cairo-png\"))");
code.addRCode("prot_heatmap <- heatmap(prot_matrix, scale=\"column\", margins=c(3,3))");
code.addRCode("dev.off()");
----------------------------------------------------------------------------
Please help if you know the work around
Hi Deepak! I have the same problem - if I get a solution I'll let you know!!!
DeleteHi again Deepak!
DeleteHere's some code that works - it's a JPanel, with button that launches the heatmap-generating code. It loads data from a .csv file and builds a heatmap from it. The .csv file is a "counts" file: there are 20 species listed in the first row, and in the second row was the number of animals of that species. Let me know if you can get it to work:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import rcaller.*;
public class HeatMap extends JPanel implements ActionListener
{
public JButton button;
public HeatMap()
{
button = new JButton("HeatMap");
button.addActionListener(this);
add(button);
}
public void actionPerformed(ActionEvent e)
{
try
{
RCaller caller = new RCaller();
caller.setRscriptExecutable("C:/Program Files/R/R-2.14.1/bin/Rscript.exe");
RCode code = new RCode();
code.clear();
File file = code.startPlot();
System.out.println("Plot will be saved to : " + file);
code.addRCode("require(gplots);");
code.addRCode("require(RColorBrewer);");
code.addRCode("setwd(\'c:/stats_data/\');");
code.addRCode("md <- read.csv(\'your_two_column_file.csv\');");
code.addRCode("cn <- 22");
code.addRCode("md <- md[order(md[,2]),]; ");
code.addRCode("n <- length(md[,1]);");
code.addRCode("n <- n + 0;");
code.addRCode("names <- md[1:n, 1];");
code.addRCode("row.names(md) <- names;");
code.addRCode("md <- md[,2:3];");
code.addRCode("mdmatrix <- data.matrix(md);");
code.addRCode("jpeg(\"theImage.jpg\")");
code.addRCode("heatmap(mdmatrix, Rowv=NA, Colv=NA, col=(colorpanel(cn, low=\"dark blue\", mid=\"gray\", high=\"red\")), scale=\"column\", margins=c(6,22));");
code.addRCode("dev.off() ");
code.addRCode("mdhm <- heatmap(mdmatrix, Rowv=NA, Colv=NA, col=(colorpanel(cn, low=\"dark blue\", mid=\"gray\", high=\"red\")), scale=\"column\", margins=c(6,22));");
code.endPlot();
caller.setRCode(code);
caller.runOnly();
code.showPlot(file);
}
catch(Exception err)
{
System.out.println("There was a problem with HeatMap");
}
}
}