Reputation: 1495
I find that if I want to import ggplot output from R into JMP using JSL scripting that I run into a problem. In JSL, I used the R Submit File
call to directly call an existing R file, rather than repeating the R script in the JSL script (this can be done by e.g. using the R Submit
JSL function).
One can ask why one would want to import an R plot into JMP as JMP has a fantastic graphics engine. I just noted this issue during a trial with JMP to R integration and thought it was good to share.
I initially raised this issue in the JMP community pages; this is a summary.
Here's the JSL:
LoadExprs = Expr(
InitR = Expr(
R Init();
);
RunR = Expr(
R Submit File( "C:\R_projects\JMP\R_JPM_integration_1.R" );
);
CapturePlot = Expr(
JMP_plot = R Get Graphics( png );
New Window( "Imported Plot", Picture Box( JMP_Plot ) );
);
RunClose = Expr(
Wait(5);
R Term(); //Close r connection
);
);
LoadExprs;
InitR;
RunR;
CapturePlot;
RunClose;
Here's the R code (just simple test code)
library(ggplot2)
library(palmerpenguins)
ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
geom_point() +
facet_wrap(. ~ island, nrow = 3)
This causes the error code Get data for "png" failed
to arise in JMP.
Upvotes: 0
Views: 168
Reputation: 1495
It turns out that we just need to explicitly plot the ggplot object in R as follows:
library(ggplot2)
library(palmerpenguins)
p <- ggplot(data = penguins, aes(x = bill_length_mm, y = flipper_length_mm, colour = species)) +
geom_point() +
facet_wrap(. ~ island, nrow = 3)
plot(p)
The ggplot plot now comes across to JMP as a png without any error message.
Upvotes: 0