Problem:
Not many examples are available of working code that allow the running of Open Source-R to generate and return graphs.
Solution:
The below TERR code calls the RinR function RGraph to return a bar chart. The interesting bit is the use of print() to return the ggbarplot() output to RGRaph.
The top section sets the path for the R.exe and checks that it exists. The path will need to be edited if required.
This code also outputs the graph to C:\temp\myplot.png as a test. It is always good to include various test output when debugging your code. Once it is working, this can then be removed.
## Load TERR's optional built-in "RinR" package ##
library(RinR)
## Set the option that will tell REvaluate() where to find open-source R: ##
FullPathToOpenSourceR <- "C:/Program Files/R/R-4.4.1/bin/R.exe"
options( RinR_R_FULL_PATH = FullPathToOpenSourceR )
## Check to see if the specified path to R exists ##
if( ! file.exists(FullPathToOpenSourceR) )
{
stop( "A path to open source R must be provided before calling REvaluate() or RGraph()." )
}
my_df <- as.data.frame(DataTable)
Graph <- RGraph(
expr = {
print(
ggbarplot(
my_df,
x="Dose",
y="Len",
add = c("mean_se", "jitter"),
color="black",
fill="red"
)
)
},
data = "my_df",
packages = 'ggpubr',
display = FALSE,
file = "C:\\TEMP\\myplot.png"
)
Graph <- as.raw( Graph )
OutputTable <- colnames(my_df)
This box will be hidden from the public.
Source Case 293766
Comments
0 comments
Article is closed for comments.