使ggvis :: export_png()工作 [英] Getting ggvis::export_png() working

查看:143
本文介绍了使ggvis :: export_png()工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ggvis图形导出为PNG文件(包括在.Rmd文档中).

Export a ggvis figure as a PNG file (for inclusion in an .Rmd document).

我对Node.js基本上一无所知,除了它很棒,而且我应该知道更多.

I know essentially nothing about Node.js, other than that it is great and I should know more.

我能做到的范围:

library(ggvis)
mtcars %>% ggvis(~mpg, ~wt) %>% export_png()
Writing to file plot.png
Guessing layer_points()

module.js:340
    throw err;
          ^
Error: Cannot find module 'd3'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/src/vega/index.js:11:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)


设置

平台

  • OS X Mavericks(10.9.5)
  • RStudio(0.98.945)
  • 使用devtools::install_github("hadley/ggvis")安装ggvis(0.3.0.9001)和依赖项
  • https://github.com/trifacta/vega克隆为/usr/local/src/vega
  • 符号链接./bin/vg2png -> /usr/local/src/vega/bin/vg2png

  • Setup

    Platform

    • OS X Mavericks (10.9.5)
    • RStudio (0.98.945)
    • Used devtools::install_github("hadley/ggvis") to install ggvis (0.3.0.9001) and dependencies
    • Cloned https://github.com/trifacta/vega to /usr/local/src/vega
    • Symlinked ./bin/vg2png -> /usr/local/src/vega/bin/vg2png
    • sessionInfo()
      R version 3.1.0 (2014-04-10)
      Platform: x86_64-apple-darwin13.1.0 (64-bit)
      
      locale:
      [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
      
      attached base packages:
      [1] graphics  grDevices utils     datasets  stats     methods   base     
      
      other attached packages:
      [1] knitr_1.6        pander_0.3.8     ggvis_0.3.0.9001 lubridate_1.3.3  dplyr_0.2.0.9001 plyr_1.8.1       stringr_0.6.2    ggplot2_1.0.0    devtools_1.5    
      
      loaded via a namespace (and not attached):
       [1] assertthat_0.1   bitops_1.0-6     caTools_1.17     colorspace_1.2-4 DBI_0.3.0        digest_0.6.4     evaluate_0.5.5   formatR_0.10     grid_3.1.0      
      [10] gtable_0.1.2     htmltools_0.2.4  httpuv_1.3.0     httr_0.5.0.9000  jsonlite_0.9.11  lazyeval_0.1.1   magrittr_1.0.1   MASS_7.3-33      memoise_0.2.1   
      [19] munsell_0.4.2    parallel_3.1.0   proto_0.3-10     Rcpp_0.11.2      RCurl_1.95-4.3   reshape2_1.4     RJSONIO_1.3-0    scales_0.2.4     shiny_0.10.1    
      [28] tools_3.1.0      whisker_0.3-2    xtable_1.7-3    
      

      推荐答案

      需要固定一些可移动的目标,以使ggvis和export_工具正常工作.

      There are a few moving targets which need to be pinned down to get ggvis and the export_ tools working.

      Vega 2+系列发行版不接受用于导出的vg2XXX命令生成的json ggvis,因此vega需要固定到v1.5.4,这是v1系列的最后一个.问题在于nodejs 4.x +不会安装vega@1.5.4,并且需要较新的vega版本.幸运的是,我们可以使用节点版本管理器(nvm)将节点版本固定到节点0.12.7,这允许我们安装vega.

      Vega 2+ series releases don't accept the json ggvis generates for the vg2XXX commands, which are used for the exporting, so vega needs to be pinned to v1.5.4 which is the last of the v1 series. The problem with that is nodejs 4.x+ wont install vega@1.5.4 and requires the newer vega versions. Thankfully we can use node version manager (nvm) to pin the node version to node 0.12.7 which allows us to install vega.

      什么是PITA,是吗?如果您在可编写脚本的容器(例如,使用 Rocker 容器)中执行此操作,则会容易得多.我一直在使用Rstudio设置,其中包括包含这些相关行的dockerfile ...

      What a PITA, yes? If you do this within a scriptable container (like with a Rocker container) environment it is much easier. I've been using a Rstudio setup that includes this dockerfile containing these pertinent lines...

      RUN \
      # Vega 2 doesn't accept the json ggvis generates when trying to use vg2XXX
      # commands so vega needs to be pinned. nodejs 4.x wont install vega@1.5.4...
      mkdir .local/lib/nvm; \
      ln -s .local/lib/nvm .nvm; \
      wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash; \
      . .nvm/nvm.sh; \
      sudo bash -c ". .nvm/nvm.sh;\
       nvm install 0.12.7;\
       nvm alias default 0.12.7;\
       npm install --silent vega@1.5.4;"; \
      ln -s -t ~/.local/bin ~/node_modules/vega/bin/*
      

      这篇关于使ggvis :: export_png()工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆