【发布时间】:2017-02-22 01:32:00
【问题描述】:
尝试在R 中使用plotly 迈出我的第一步。
我想将我的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 从我的Mac 连接到我的linux 系统。
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
有什么想法吗?
顺便说一句,
我正在使用plotly_4.5.6 和ggplot2_2.2.1
【问题讨论】:
-
谢谢。我注意到并修复了它,但错误是无关的。
-
已修复。再次感谢。
-
在 win7 上与相同版本工作正常
-
在 Mac 上也能正常工作。问题是 Linux 特有的
-
不是解决方法,但可以解决...创建一个 rMarkdown 对象,其中只有绘图...您将拥有一个交互式 html 文档