我试图将一个情节图表包含在带有knitr的Latex文档中。由于knitr包含webshot包,因此效果很好。但是,如果我想调整乳胶输出的数字,图形环境会变大,但是图表图表不会被调整到手动设置的图形宽度和高度。
指定推荐here等网页提示选项,但两者都不起作用。缩放ggplot图表效果很好,但如何才能获得相同的结果图表?
\documentclass{article}
\usepackage{cleveref}
<<setup, echo=FALSE, message = FALSE, warning = FALSE>>=
library(ggplot2)
library(plotly)
@
%Preamble
\title{GGplot vs. Plotly }
\author{authors}
\date{2016}
\begin{document}
\maketitle
\section{Comparison ggplot with plotly}
This document illustrate the difference between ggplot and plotly. The chart in (\Cref{fig:ggplot}) is well placed in the document, but the chart in (\Cref{fig:plotly}) is neither scalled to the figure width, nor positioned next to the label.
<<ggplot, fig.lp="fig:", fig.cap = 'This is rendered with ggplot()', echo=FALSE, fig.width = 10, fig.height = 6>>=
ggplot(midwest, aes(x = state, y = percollege, colour = state)) + geom_boxplot()
@
<<plotly, fig.lp="fig:", fig.cap = 'This is rendered with plotly()', echo=FALSE, fig.width = 10, fig.height = 6, screenshot.opts = list(delay = 2, cliprect = 'viewport')>>=
plot_ly(midwest, x = ~state, y = ~percollege, color = ~state, type = "box")
@
\end{document}
我看到图形文件 figure / plotly-1.pdf (由knitr / webshot生成,然后加载到latex中)有两页,而plotly对象位于左上角的某处。我想webshot数字中包含的边距实际上是问题所在。
R 3.2.3 knitr 1.14 ggplot2 2.1.0 情节4.5.2