[R] [External] Extracting Plot Arguments

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Fri Feb 23 18:11:46 CET 2024

Does the grid.echo function in the gridGraphics package do what you want?

Convert a scene that was drawn using the graphics package to an identical scene drawn with the
grid package.

> On Feb 21, 2024, at 22:49, Reed A. Cartwright <racartwright using gmail.com> wrote:
> Hi All,
> I'm building an autograding framework for my biostatistics class this
> semester, and I am exploring different ways to automatically grade
> figures.
> In other classes, I teach ggplot2 and I extract information directly
> from the ggplot2 object. However, in this class we are using base R
> and I need to extract information from base-r graphics.
> I've tried several different approaches, but I'm not sure which one is
> the easiest and most effective. Has anyone ever tried this? Are there
> any packages to help with this?
> (1) Storing `recordedplots` objects and trying to extract information
> from them. This data structure felt very low level, and I wasn't sure
> how easy it was to map the results to user-level function calls.
> (2) Use the `svglite` device to produce svg files, which can be
> parsed. This also worked, but required a lot of code to parse the
> resulting images and identify things like labels, and coordinate
> locations. I got tired of having to figure how to extract information
> from an SVG.
> (3) Use a wrapper on specific graphics functions that records the
> function arguments. This turns out to be a bit too high level, as I
> have to manually massage inputs. E.g. handle both xy plots and formula
> + data plots. (We teach both styles.)
> Are there any other ideas that I can try? My students are using an
> RMarkdown worksheet and answering questions by putting code in
> specific chunks. I've already hooked into knitr so I can record the
> chunk lines as they are being run and  get the results and
> side-effects.
> Thanks,
> Reed
> --
> Reed A. Cartwright, PhD
> Associate Professor of Genomics, Evolution, and Bioinformatics
> School of Life Sciences and The Biodesign Institute
> Arizona State University
> ==================
> Address: The Biodesign Institute, PO Box 876401, Tempe, AZ 85287-6401 USA
> Packages: The Biodesign Institute, 1001 S. McAllister Ave, Tempe, AZ
> 85287-6401 USA
> Office: Biodesign B-220C, 1-480-965-9949
> Website: http://cartwrig.ht/
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list