[Rd] Creating a text-based device/output format
David McArthur
D@v|d@McArthur@2 @end|ng |rom g|@@gow@@c@uk
Tue Jun 25 11:42:59 CEST 2024
Hi there, I hope I am sending this message to the right list.
This is a “where should I start?” type question.
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:
https://mermaid.js.org/syntax/xyChart.html
This project aims to have plain text representation of graphics in markdown files, which when converted to HTML (either at compile time or at runtime), can turn these “mermaid” code blocks into a diagram/plot via a JavaScript parser and plotting library.
This has inspired me to attempt to create a proof-of-concept for R 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:
title "The body mass (g) of penguin species"
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]
How should I go about this in R? I feel I should be aiming to create a new “device” or “output format”, but I haven’t found any examples on how to do this.
One of my colleagues suggested I hook into ggplot_build, but then of course the project would be limited to ggplot plots.
Any help greatly appreciated 😊
Thanks,
David McArthur
School of Mathematics & Statistics
University of Glasgow
[[alternative HTML version deleted]]
More information about the R-devel
mailing list