Rendering Graphics with R using RConnect

Using Dyalog under 'nixes

Rendering Graphics with R using RConnect

Postby mhpcto on Fri Aug 05, 2022 11:31 pm

I have been using R from APL quite a bit but have rarely done any graphics via R.

The example graphics output in the R Interface Guide works fine.

I had a need to display a US map and chose the "usmap" and "ggplot2" packages. From R, both commandline and RStudio, these packages work fine and open graphics windows but I can't make it work via RConnect.

The simplest test is (in R):

> library(usmap); library(ggplot2); plot_usmap()

This will open a graphics window and show a US map.

If I execute the same via r.x from APL I get ... nothing.

⎕←r.x 'library(usmap); library(ggplot2);plot_usmap()'
gtools ggplot2 usmap stats graphics grDevices utils datasets methods

What am I missing?
Posts: 18
Joined: Tue Sep 18, 2018 5:36 pm

Re: Rendering Graphics with R using RConnect

Postby Vince|Dyalog on Mon Aug 08, 2022 1:20 pm

Hi mhpcto,

1) I have searched the internet, and found a suggestion about using the print method.
r.x 'print(plot_usmap())'

2) Our rscproxy does not seem to work with the latest R 4.2. For the future, we now recommend an interface to R called rsconnect that a customer Kimmo Linna wrote. You can get it on github.

I have put it in D:\git\rsconnect\ on my computer.
      ]load D:\git\rsconnect\rserve.dyalog
r←⎕NEW #.RS.Rserve
r.eval 'library(usmap)'
r.eval 'library(ggplot2)'
r.eval 'print(plot_usmap())'
r.eval 'print(plot_usmap())'

I did find that I needed to make the call twice to get the display to update, and I will log that as an issue.


Posts: 378
Joined: Wed Oct 01, 2008 9:39 am

Re: Rendering Graphics with R using RConnect

Postby mhpcto on Tue Aug 16, 2022 11:55 pm

Thanx for the input. Based on your response I did dive a little deeper into R plotting and how to render and save plots.

While plotting and viewing is kinda 1980's primitive (I have not found a way to pop up a graphics window that has controls for resizing, scaling, saving, etc. the way the RStudio graph window does) it seems to work with R 4.2 and rconnect. I will give the alternative a try.

Displaying graphs is working ok, but graph saving is a mess even in R native. I found that I can actually save a graph being displayed with 'dev.copy(svg, "myfile.svg") (many supported formats) but the file gets written only after I call ''!?!
Posts: 18
Joined: Tue Sep 18, 2018 5:36 pm

Return to UNIX and Linux

Who is online

Users browsing this forum: No registered users and 1 guest