Creating a text-based device/output format
On 25/06/2024 10:42, David McArthur wrote:
Hi there, I hope I am sending this message to the right list.
This or r-package-devel.
This is a ?where should I start?? type question.
With the R-Internals manual and the grDevices sources and the examples there. Another possibility is to translate one of the several 'text-based' graphics formats already supported, including postscript ASCII PDF svg xfig pictex and others in packages (R2SWF devEMF httpgd tikzDevice ...). The quality of R graphics depends heavily on the precise positioning of (possibly non-ASCII) text, and so font-handling is by far the hardest part of writing a graphics device (and I have written several). So it makes sense to leverage what is already done, by modifying sources or translating output. This would have been easier if graphics standards and R-at-the-time supported UTF-8, and the lack of such support is why some of these have been deprecated.
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]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Brian D. Ripley, ripley at stats.ox.ac.uk Emeritus Professor of Applied Statistics, University of Oxford