Documentation

43.19 R in the browser and the Plot builder

Two cards, Explore in R with webR and Plot builder with Vega-Lite, both saving into the run

What you will learn

  • What the R terminal in the browser provides.
  • What the Plot builder draws and how it saves ggplot2 scripts.
  • How Save to run keeps your own work with the run.

Two ways to go beyond the standard views

Standard plots and tables answer the usual questions. When you need another view, you should not have to leave the run. Two tools are built into every results panel.

Explore in R

Explore in R opens a full-window R workspace that runs in your browser (R compiled to WebAssembly, webR). It has an editor, console, environment, files, plots and tables, and packages such as the tidyverse, ggthemes, patchwork and PKNCA. The dataset and the result tables of the run are mounted in R's working directory, with a starter script written for the command, for example:

  • the final-estimates row of an .ext file after a fit;
  • a VPC band plot;
  • a forest plot of forest_results.csv;
  • in NCA, a PKNCA cross-check, so a second implementation can be compared in the same window.

The R runtime loads once and is cached afterwards. Nothing about your data is sent anywhere to run R: it runs on your device.

The R window has a script name and Save to run: this writes R/webr/<name>.R and the files made in R's working directory into the run, so the script and its outputs travel with the results.

The Plot builder

The Plot builder sits in the results header next to Explore in R. It is a full-window workspace that draws any table of the run in the browser with Vega-Lite, with no R needed.

  • Plot types: scatter, line, line plus points (with a mean or median line by x or by bins), mean plus or minus SE, box plot, violin, histogram (bin width as in ggplot2), density and bar.
  • Themes and panels: 16 ggplot-style themes (Classic by default), ggplot2's colours, panels by one or two columns, log or swapped axes.
  • Zoom, select and move: drag a box to zoom, drag the plot to move it, zoom with Ctrl or Cmd and the wheel around the pointer, and Reset. The zoom is saved with the page and written to the R code.
  • Histograms with a number of bins or a bin width, where a bin starts, which end is included, count or density, and stack, overlap, dodge or fill.
  • Pages: one page per plot.

Save page to run writes the picture, the ggplot2 script that draws the same plot, and the settings into the run's R/builder/ folder. The files appear in the run's Files tab at once. That means a point-and-click plot becomes reproducible code in one click.

Size handling

Up to 20,000 rows are plotted so the page stays fast. A bigger table is cut down first with Exclude rows where rules or Rows to plot (first n, a random sample of n, or every k-th row). A random sample drawn in the browser is not the same set of rows as R's sample(), which the page notes.

Available everywhere

Explore in R and the Plot builder are in the single apps, in One, and in Maxson and Super. In the studio apps (Prep, BE & DDI, Trial) the views are built in, with an export of tables and figures instead.

Why this matters

Two failure modes of automated analysis are a plot nobody can modify and a modified plot nobody can reproduce. Here the standard plot is a click, the custom plot is another click, the code for it is saved with the run, and the R terminal is there for the rest. A figure in a manuscript can be traced to a script in a run folder.

See the previous page, next page, and the chapter overview.