2017-02-22 44 views
0

试图使用plotlyR中完成我的第一步。将ggplot2对象保存为gglotlot并保存到Linux中的磁盘

我想将我的ggplot2对象转换为ggplotly对象,然后在Linux平台上将它保存为html。我希望能够从命令行调用此R代码并将其作为脚本执行,而不是通过RStudio运行它。

我认为这会做(from plotly's manual):

require(ggplot2) 
require(plotly) 

ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species) 
ggiris.ly <- ggplotly(ggiris) 
htmlwidgets::saveWidget(ggiris.ly,"ggiris.html") 

ggplotly(ggiris)抛出这个错误:

Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, : 
    unable to start device PNG 
In addition: Warning message: 
In dev_fun(tmpPlotFile, width = deviceWidth, height = deviceHeight) : 
    unable to open connection to X11 display '' 

我再装XQuartz能够ssh -X -Y从我Maclinux系统。

ggiris.ly <- ggplotly(ggiris) 

打开R Graphics设备,但随后

htmlwidgets::saveWidget(ggiris.ly,"~/Downloads/ggiris.html") 

抛出这个错误:

Error in htmlwidgets::saveWidget(ggiris.ly, "~/Downloads/ggiris.html") : 
    Saving a widget with selfcontained = TRUE requires pandoc. For details see: 
https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md 

任何想法?

BTW, 我使用plotly_4.5.6ggplot2_2.2.1

+0

谢谢。我注意到并修复了它,但错误与此无关。 – user1701545

+0

固定。再次感谢。 – user1701545

+0

与win7上的相同版本可以正常工作 – HubertL

回答

0

我保证我没有当ssh -X从我的Mac我的远程服务器上firewall

然后上面的代码在没有警告的情况下执行。 (期望从打开空的图形设备创建空白Rplot.pdf文件)。

0

您需要在您的系统上安装pandoc。要么运行sudo apt-get install pandoc,要么让系统管理员在没有root权限的情况下这样做。

或者,您可以使用保存htmlwidgets::saveWidget(h, "test.html", selfcontained=FALSE)