An Implementation of the 'SGL' Graphics Language

Generates plots from a database connection and a 'SGL' statement. 'SGL' is a graphics language designed to look and feel like 'SQL'. It is especially useful for those familiar with 'SQL' who want to specify plots in a similar manner. The 'SGL' language is described in Chapman (2025) .


rsgl

R-CMD-check

rsgl implements the SGL graphics language for use within R. SGL is a graphics language that is designed to look and feel like SQL, and is based on the grammar of graphics.

Installation

To install the official CRAN release:

install.packages("rsgl")

If you instead want the development version, install from GitHub with:

# install.packages("devtools")
devtools::install_github("sgl-projects/rsgl")

Usage

dbGetPlot is the primary interface to rsgl. It takes a DBI database connection and a SGL statement and returns the corresponding plot.

The following example demonstrates creating a DBI connection to an in-memory DuckDB database, loading it with data, and then generating a scatterplot from a SGL statement.

library(duckdb)
#> Loading required package: DBI
library(rsgl)
#> 
#> Attaching package: 'rsgl'
#> The following objects are masked from 'package:datasets':
#> 
#>     cars, trees

con <- dbConnect(duckdb())
dbWriteTable(con, "cars", cars)

dbGetPlot(con, "
    visualize
        horsepower as x,
        miles_per_gallon as y
    from cars
    using points
")

Next steps

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rsgl")

0.1.0 by Jon Chapman, 4 months ago


https://github.com/sgl-projects/rsgl, https://sgl-projects.github.io/rsgl/, https://arxiv.org/abs/2505.14690


Report a bug at https://github.com/sgl-projects/rsgl/issues


Browse source code at https://github.com/cran/rsgl


Authors: Jon Chapman [aut, cre, cph] , Free Software Foundation , Inc. [cph] (Bison parser skeleton)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports DBI, dplyr, duckdb, ggplot2, purrr, Rcpp, rlang

Suggests testthat, vdiffr, lubridate, knitr, rmarkdown, patrick, tibble, withr

Linking to Rcpp


See at CRAN