code.mindmeldr.com /graphterm

Previous topic

Using the GraphTerm Virtual Computer Lab

Next topic

GraphTerm toolchain and features

This Page

Using GraphTerm with RΒΆ

GraphTerm supports basic inline graphics display and the notebook interface using R. The file $GTERM_DIR/bin/gterm.R includes helper functions for using the GraphTerm API to display inline graphics. The following R packages need to be installed: RCurl, Cairo, and png. On Linux, the following additional libraries, or their equivalents, may need to be installed: libcurl4-openssl-dev libcairo2-dev libxt-dev. Here’s a plotting example:

$ R -q
>  gterm <- paste(Sys.getenv("GTERM_DIR"),"/bin/gterm.R", sep="")
>  source(gterm)          # Load GraphTerm API helper functions
>  g <- gcairo()          # Initialize Cairo device for GraphTerm output
>  x <- rnorm(100,0,1)
>  hist(x, col="blue")
>  g$frame()              # Display plot as inline image
>  hist(x, col="red")
>  g$frame(TRUE)          # Overwrite previous plot
>  hist(x, col="green")
>  g$frame()              # New plot
https://github.com/mitotic/graphterm/raw/master/doc-images/gt-r.png

The notebook mode of GraphTerm will also work with R, without any additional software. GraphTerm can open Markdown files (in a format very similar to R-markdown) as a notebook, and also saves notebooks using the same format. The file $GTERM_DIR/notebooks/R-histogram.R.md contains a sample notebook displaying inline graphics (see Inline plotting with R). To open the notebook, click on it in the gls output, or use the notebook/open menu option after starting R.

https://github.com/mitotic/graphterm/raw/master/doc-images/gt-r-nb.png