[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 17:42:38 CEST 2024


Many thanks for your reply, Brian.

Ivan has suggested an R device is probably not where I should aim to make this mermaid plain text syntax as by this point I would be dealing with shape primitives instead of, eg. a histogram and its values.  This makes sense to me, but if you have other ideas please let me know.

I’ll aim to write something to output mermaid-like syntax from ggplot2 as an initial experiment, probably in toml format for ease of serialising and parsing.  If this concept works, and I get feedback that it is a helpful addition to accessibility from visually impaired students in my research group, I’ll report back here with some demos.

Thanks again,

David McArthur
School of Mathematics & Statistics
University of Glasgow

From: Prof Brian Ripley <ripley using stats.ox.ac.uk>
Date: Tuesday, 25 June 2024 at 14:24
To: David McArthur <David.McArthur.2 using glasgow.ac.uk>, r-devel using r-project.org <r-devel using r-project.org>
Subject: Re: [Rd] 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://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmermaid.js.org%2Fsyntax%2FxyChart.html&data=05%7C02%7CDavid.McArthur.2%40glasgow.ac.uk%7Cc73e08abcba743458fd708dc951a1786%7C6e725c29763a4f5081f22e254f0133c8%7C1%7C0%7C638549186500457747%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=oHSSn%2BhGl7TFKT91TWsQB8MtDoSMplY8l8GJmv%2Bd8B4%3D&reserved=0<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 using r-project.org mailing list
> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-devel&data=05%7C02%7CDavid.McArthur.2%40glasgow.ac.uk%7Cc73e08abcba743458fd708dc951a1786%7C6e725c29763a4f5081f22e254f0133c8%7C1%7C0%7C638549186500467131%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=Km8OqjoWeDXhBsKild%2Brr4ZgRCId2nmZARzSItxkN7Y%3D&reserved=0<https://stat.ethz.ch/mailman/listinfo/r-devel>

--
Brian D. Ripley,                  ripley using stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford

	[[alternative HTML version deleted]]



More information about the R-devel mailing list