无法将绘图图表从R swave编译为pdf

无法将绘图图表从R swave编译为pdf,r,latex,plotly,R,Latex,Plotly,我无法将R swave中plotly创建的图表转换为Pdf。但也可以创建其他图表。plotly图表是否需要添加其他代码 下面是一个例子 \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} <<echo = FALSE>>= C1<-c("A","B","C") C2<-c(10,20,30) Df<-data.frame(C1,C2) @ \begin {f

我无法将R swave中plotly创建的图表转换为Pdf。但也可以创建其他图表。plotly图表是否需要添加其他代码

下面是一个例子

\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}



<<echo = FALSE>>=
C1<-c("A","B","C")
C2<-c(10,20,30)
Df<-data.frame(C1,C2)
@

\begin {figure}

<<echo = FALSE, fig = TRUE>>=
suppressWarnings (library (plotly))
plot_ly(Df, x = ~C1, y = ~C2, type = "bar")%>% layout(title = "ABC")
@

 \caption {PlotlyChart}
 \end {figure}

 Normal Chart

\begin {figure}

<<echo = FALSE, fig = TRUE>>=
barplot(Df[ ,2], names.arg = Df[ ,1])
@

\caption {Normal_Chart}
\end {figure}

\end{document}

我对R Swave和Latex不熟悉,因此非常感谢您的帮助。谢谢

Plotly生成绘制绘图的javascript代码。此代码将在web浏览器中执行。Plotly仅在生成HTML文档时可用。没有PDF,没有乳胶

但是您可以将package
webshot
phantomjs
一起使用,将绘图保存为图像,然后将图像包含为图形

首先安装webshot:

install.packages("webshot")
webshot::install_phantomjs()
然后修改保存文件,如下所示:

\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}

<<echo = FALSE>>=
C1<-c("A","B","C")
C2<-c(10,20,30)
Df<-data.frame(C1,C2)
@

<<echo = FALSE, fig = FALSE>>=
suppressWarnings (library (webshot))
suppressWarnings (library (plotly))
py <- plot_ly(Df, x = ~C1, y = ~C2, type = "bar")%>% layout(title = "ABC")
export(py, file = "myplot.png")
@
\begin {figure}
\includegraphics{myplot.png}
\end {figure}

\end{document}
\documentclass{article}
\开始{document}
\SweaveOpts{concordance=TRUE}
=

这是一个非常有趣的解决方案。同样值得注意的是,
phantomjs
作为一个独立的终端工具工作,如果您只想生成Plotly HTML输出的静态图像,这可能很有用。
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}

<<echo = FALSE>>=
C1<-c("A","B","C")
C2<-c(10,20,30)
Df<-data.frame(C1,C2)
@

<<echo = FALSE, fig = FALSE>>=
suppressWarnings (library (webshot))
suppressWarnings (library (plotly))
py <- plot_ly(Df, x = ~C1, y = ~C2, type = "bar")%>% layout(title = "ABC")
export(py, file = "myplot.png")
@
\begin {figure}
\includegraphics{myplot.png}
\end {figure}

\end{document}