简体   繁体   English

第三方R库的FsLab和R图

[英]FsLab and R Plots from 3rd party R Libraries

Can FsLab/f# formatting handle arbitrary R Visualisation from 3rd party libraries? FsLab / f#格式可以处理来自第三方库的任意R可视化吗?

I have been trying to include an igraph chart without success. 我一直试图包括一张图的图表。

I can get a (very) simple graph plot to pop up out of fsi by evaluating this: 通过评估以下内容,我可以得到一个(非常)简单的图形,从fsi中弹出:

#load "packages/FsLab/Themes/DefaultWhite.fsx"
#load "packages/FsLab/FsLab.fsx"

open Deedle
open FSharp.Data
open RProvider
open RProvider.graphics
open RProvider.igraph

let grpa = R.graph__from__literal("A--B, B-c")
let pl = R.plot_igraph(grpa)

but if I try to include it in a journal with: 但是如果我尝试将其包含在以下日志中:

(*** include-value:pl ***)

I just get the output RDotNet.SymbolicExpression included. 我只是得到包括输出RDotNet.SymbolicExpression

Am I missing something here? 我在这里想念什么吗?

(the pop up graph itself also doesn't look quite right but i guess that's a different problem!) (弹出图本身看起来也不太正确,但是我想这是一个不同的问题!)

The FsLab template was somewhat unreliable at doing this, so I decided to remove the partial support that used to be there for the time being (it would be nice to get it back, but it should work properly :-)). FsLab模板在执行此操作时有些不可靠,因此我决定删除暂时存在的部分支持(很高兴找回它,但它应该可以正常工作:-))。

My recommendation is to write a helper function that captures the R output into an image and then return the image. 我的建议是编写一个辅助函数,将R输出捕获到图像中,然后返回图像。 I don't have R installed to test this, but something along these lines should work for R.plot at least: 我没有安装R来测试它,但是至少对于R.plot ,这些方法应该适用:

let capture f = 
  let file = Path.GetTempFileName() + ".png"   
  R.png(file) |> ignore
  let res = f()
  R.dev_off()
  let img = Image.FromStream(new MemoryStream(File.ReadAllBytes file))
  File.Delete(file)
  res, img

Then you would be able to create charts using: 然后,您将可以使用以下方法创建图表:

let pl, img = capture(fun () ->  
  R.plot(...) )

As for using this with igraph - I'm not sure, but tutorials on how to save igraph output to a file should help. 至于将其与igraph一起使用-我不确定,但是有关如何将igraph输出保存到文件的教程应该会有所帮助。 One thing I noticed is that you sometimes need to call R.show to get things to render, so perhaps try: 我注意到的一件事是您有时需要调用R.show来进行渲染,所以也许尝试:

let _, img = capture(fun () ->  
  R.plot_igraph grpa |> R.show )

(*** include-value:img ***)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM