/* Plot Functions with R v5 Julian L. Parris Ph.D. 2018 */ // Expressions List LoadExprs = expr( InitR = expr( R Init(); R Submit( " library(ggplot2) library(plyr) library(UsingR) " ); ); MakeOPlot = expr( yy = yvar << Get Items; group = xvar << Get Items; rNameY = R JMP Name to R Name( yy[1] ); rNameX = R JMP Name to R Name( group[1] ); dt = Current Data Table(); R Send(dt); //Based on checkbox, either plot with or without mean lines If( cb << Get == 1, DensityWithMeans, DensityNoMeans); ); MakeVPlot = expr( yy = yvar << Get Items; xx = xvar << Get Items; rNameY = R JMP Name to R Name( yy[1] ); rNameX = R JMP Name to R Name( xx[1] ); //print(y[1]); dt = Current Data Table(); R Send(dt); R Submit( EvalInsert("\[simple.violinplot(^rNameY^ ~ ^rNameX^,data=dt, col = "lightgray")]\")); ); DensityWithMeans = expr( //Calculate means for y based on grouping variable provided R Submit( EvalInsert(" \[ cdf <- ddply(dt, "^rNameX^", summarise, ^rNameY^.mean=mean(^rNameY^)) ]\" ) ); //Generate Plot R Submit( EvalInsert("\[ ggplot(dt, aes(x=^rNameY^, fill=^rNameX^)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=^rNameY^.mean, colour=^rNameX^), linetype="dashed", size=1) ]\") ); ); DensityNoMeans = expr( R Submit( EvalInsert("\[ ggplot(dt, aes(x=^rNameY^, fill=^rNameX^)) + geom_density(alpha=.3) ]\") ); ); CapturePlot = expr( JMP_plot = R Get Graphics(png); New Window("Imported Plot", Picture Box(JMP_Plot)); ); RunClose = expr( inwin << Close Window; // close window R Term( ); //Close r connection ); ); LoadExprs; //load all the expressions that reside at the end of the file InitR; //Start R Connection and load libraries // Prompt for data table if none is open if(IsEmpty(Current Data Table()), dt = Open(), dt = Current Data Table()); //Draw Window and Create Fields and Buttons inwin = New Window( //Draw New Window and name inwin "R Plotting", //Window Title Panel Box("Specify Columns for R Plots", //Draws visible box H List Box( //Invisible box for layout - glues horizontally clb1 = Col List Box( all ), //Column listbox, with name clb1 so we can access later // Draw First Lineup Box (invisible, provides arrangement) for Selecting Columns Lineup Box( N Col( 2 ), //with 2 columns indicated, each pair will span a row //First Row Button Box( "Response", yvar << setitems( clb1 << getselected ) ), yvar = Col List Box( minitems( 1 ), maxitems( 1 ), nlines( 1 ) ), //Second Row Button Box( "Groups", xvar << setitems( clb1 << Get Selected ) ), xvar = Col List Box( minitems( 1 ), maxitems( 1 ), nlines( 1 ) ), //Third Row Spacer Box( size( 10, 10 ) ), cb = Check Box( "Plot Means", <