plaintext output from ggplot2 plotting functions

Hi there,

This is a “where should I start?” type question for ggplot2 experts.

I am a JavaScript developer, working on ideas for more accessible Maths and Stats coursework. I have worked with RMarkdown and knitr extensively to create HTML coursework but I’m by no means an R developer!

I recently came across a project called mermaid.js, which is designed for diagrams but has limited charting syntax.

This project aims to have plain text representation of (mainly) diagrams in markdown fenced code blocks labelled "mermaid", which can be (either at compile time or at runtime) converted into a diagram/plot using a frontend JavaScript parser and plotting library.

This has inspired me to attempt to create a proof-of-concept for ggplot2 along these lines.

For example this R code:

library(ggplot2)
library(palmerpenguins)
 
ggplot(data, aes(x=body_mass_g,fill = species)) +
  geom _histogram()

Could output something like:

x-axis "Body mass (g)" 3000 --> 5550
y-axis "Count" 0 --> 2
histogram
  Adelie [3000, 3250, 3400]
  ChinStrap [3250, 3600]
  Gentoo [4300, 5050, 5200, 5300, 5450]

Does anyone have advice as to how I should go about this, and point me in the right direction?

I've seen the ggplot_build output which looks promising.

I'm mainly working with RMarkdown documents, and ideally I'd like to leave the code chunks unchanged and "monkey patch" the plotting functions if that's possible in R? I've tried a few things but so far haven't figured it out.

Any help greatly appreciated :slight_smile:

Thanks,

David McArthur