Pages

Thursday, September 23, 2010

Using JMP 9 and R Together

An R Graph in JMP

JMP 9 is now able to talk to the popular open source statistical software R.


JMP Scripting Language (JSL) is what allows JMP and R to work together.

Here are the most useful JSL functions for R:

//initialize the R session: 
RInit()

//send a JMP object to R:
int RSend(JMPObject)

//get an object from R:
object = RGet(RVariableName)

//submit R code to R for processing: 
int RSubmit(RCode)

//get the last graph made by R:
picture = RGetGraphics(format)

//terminate the session: 
int RTerm() 

Here is a simple program:
  • Open a sample table in JMP
  • Send the data to R
  • Make a scatterplot matrix in R
  • Return the graph to JMP and display it

//open a JMP table:
dt = Open("$SAMPLE_DATA/Big Class.JMP", invisible(true));

//initialize the R session (R must be installed on your computer):
RInit();

//send the JMP data table to R:
result = RSend(dt);

//execute the R code. Make a scatterplot matrix:
RCode = "plot(dt)";
result = RSubmit(RCode);

//get the plotted graphic from R:
graphic = RGetGraphics(png);

//plot the graphic in JMP:
NewWindow("Graph from R", PictureBox(graphic));

//terminate the session:
result = RTerm();

Easy huh? The graphic at the top of this posting was done via the above code.

1 comment: