CoCalc
Sharedsupport / 2015-11-05-170512-r-plots.sagewsOpen in CoCalc

Examples for support purposes...

Andrey N. says:

OK, here is my take on R plots: http://sagecell.sagemath.org/?z=eJwryMkv0SjKyy_K1TA0MNDU5OUqwBDJKkhN1yjPTCnJsDUGimBTUpCSpoFdAkMkOTGzKD8epCE_LzUtMyfV1s3RJ9iVSN3FZekaIE15ibmptkrOpcUl-bl6QEElrKoB67NCZQ==&lang=r

SageMathCell now defaults to producing SVG plots in R and displays all automatic plots that it can (BMP, JPEG, PNG, SVG). Users are free to start new plotting devices, pass any options to them, and create multiple plots in the same cell. Plots with custom names or harder formats like PDF will be provided as links only. With SageMathCloud approach you cannot change format and changing options is done not from R code using R commands, you are also limited to a single plot displayed automatically. The code above does not show any plots at all in the cloud.

What had to be done:

  1. R interface is recreated after each forking (via "r=R()" command) to make sure that a new working directory is picked up. Would be great if interfaces followed changing directories of the main process, but I don't know how feasible that is.
  2. There is site configuration file installed into R in Sage setting two options including default graphing device SVG. In Sage R interface is prohibited from picking up configuration from anywhere and device is forced in addition - I had to change it and I think it makes a lot of sense to change it for Sage itself.
  3. After each R cell is executed, all graphic devices are now closed and plots with default R names are shown automatically if possible. (Everything else gets a link to.) R plots produced not in "R cells" will be always linked to only, without auto display - this is similar to cloud showing plots only if r-decorator was used.
%r

plot(rnorm(100))
plot(rnorm(100))
jpeg(width=300)
plot(rnorm(100))
pdf()
plot(rnorm(100))
plot(rnorm(100))
cairo_pdf(onefile=FALSE)
plot(rnorm(100))
plot(rnorm(100))
svg(filename="Custom.svg")
plot(rnorm(100))