【发布时间】:2018-09-22 03:41:08
【问题描述】:
我目前正在使用 R 的 ggplot2 和 tikzDevice 包来生成图形并在 LaTeX 文档中介绍它们,但是我正在努力解决在图形和标题之间产生的大空白,因为你可以看看你是否比较图像(我已经手动突出显示空间以使其更清晰):
这是我的 MWE:
R 代码:
library(ggplot2)
library(tikzDevice)
set.seed(1)
x <- rnorm(200)
tikz(file = "Rplots.tex", width = 4, height = 4)
qplot(x, geom = "histogram")
dev.off()
和 LaTeX 代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\include{Rplots}
\caption{\texttt{ggplot2} plot.}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}[scale=3]
\clip (-0.1,-0.2)
rectangle (1.8,1.2);
\draw[step=.25cm,gray,very thin]
(-1.4,-1.4) grid (3.4,3.4);
\draw (-1.5,0) -- (2.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle (1cm);
\filldraw[fill=green!20!white,
draw=green!50!black]
(0,0) -- (3mm,0mm)
arc (0:30:3mm) -- cycle;
\end{tikzpicture}
\caption{\texttt{tikz} plot.}
\end{figure}
\end{document}
我想知道如何消除标题和图形之间的巨大空间通过 ggplot2。
PS。 R 版本:3.2.3,ggplot2 版本:2.1.0,tikzDevice 版本:0.10-1。我从 Tobias Oetiker 的 The Not so Short Introduction to LaTeX 2e,版本 5.05,第 116 页中获取了第二个情节的代码。
【问题讨论】:
-
您是否尝试过通过 ggplot2 主题更改绘图边距?我仍然不明白它是如何特定于 tikz 设备的。如果您查看我在下面发布的示例,则会为 pdf 设备获得完全相同的边距。