Icon

k_​001_​r_​multiple_​export

Multiple plots / graphs from a single R script

You could determine a local path and then tell R to save various graphics in a row. I attached an example workflow that does that. You might use that as a starter.

The R View shows one plot but saves more than one. I tried that with just a R scrip node but it gave me an error message.

Multiple plots / graphs from a single R scripthttps://forum.knime.com/t/multiple-plots-graphs-from-a-single-r-script/12746 # library(tidyverse)library(gridExtra)library(ggplot2)# https://www.andrewheiss.com/blog/2016/12/08/save-base-graphics-as-pseudo-objects-in-r/var_name_pdf_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.pdf")var_name_png_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.png")# Scatterplotp1 <- ggplot(rframe, aes(x=x, y=y, color=z)) + geom_point()# Distributionp2 <- ggplot(rframe, aes(x=y, fill=z)) + geom_density(alpha=0.5)# p.both <- arrangeGrob(p1, p2)# grid::grid.draw(p.both)ggsave(p1, filename=var_name_pdf_file)ggsave(p2, filename=var_name_png_file)plot(p1) create datadeterminepath and name of workflowvar_pos_namevar_path_parent_folderdetermine file separatorvar_path_graphic R Source (Table) Extract ContextProperties (deprecated) Variable to TableRow (deprecated) String Manipulation String Manipulation Extract SystemProperties Java Snippet(simple) Table Column toVariable (deprecated) Table Row to Variable(deprecated) R View (Workspace) Table to R Multiple plots / graphs from a single R scripthttps://forum.knime.com/t/multiple-plots-graphs-from-a-single-r-script/12746 # library(tidyverse)library(gridExtra)library(ggplot2)# https://www.andrewheiss.com/blog/2016/12/08/save-base-graphics-as-pseudo-objects-in-r/var_name_pdf_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.pdf")var_name_png_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.png")# Scatterplotp1 <- ggplot(rframe, aes(x=x, y=y, color=z)) + geom_point()# Distributionp2 <- ggplot(rframe, aes(x=y, fill=z)) + geom_density(alpha=0.5)# p.both <- arrangeGrob(p1, p2)# grid::grid.draw(p.both)ggsave(p1, filename=var_name_pdf_file)ggsave(p2, filename=var_name_png_file)plot(p1) create datadeterminepath and name of workflowvar_pos_namevar_path_parent_folderdetermine file separatorvar_path_graphicR Source (Table) Extract ContextProperties (deprecated) Variable to TableRow (deprecated) String Manipulation String Manipulation Extract SystemProperties Java Snippet(simple) Table Column toVariable (deprecated) Table Row to Variable(deprecated) R View (Workspace) Table to R

Nodes

Extensions

Links