tikz 및 r을 사용하여 그래픽 앞뒤 공백 제거

tikz 및 r을 사용하여 그래픽 앞뒤 공백 제거

R에서 플롯을 생성한 후 라텍스 프로젝트에서 이를 사용하고 싶었습니다. 그러나 플롯 전후에 공백이 많이 있는 것 같습니다. 누구든지 그것을 제거하도록 도와줄 수 있나요? 나에게는 이것이 R에서 수행되는지 아니면 Latex에서 수행되는지는 중요하지 않습니다.

문제:

여기에 이미지 설명을 입력하세요

먼저 R 코드

tikz('dataBrakePads.tex', width = 5.75, height = 3)
scatterplot3d(df$width, 
              df$length, 
              df$thickness, 
              pch=16, 
              color=df$colors,
              type="h", 
              lty.hplot=3, 
              xlab = xlab,
              ylab = ylab,
              zlab = zlab) 
dev.off()

이제 꽤 긴 .tex 파일이 생겼습니다. 하지만 파일 길이 때문에 일부 포인트를 제거했습니다. 이 부분은 세 개의 점으로 표시됩니다.

% Created by tikzDevice version 0.10.1 on 2018-02-14 19:26:18
% !TEX encoding = UTF-8 Unicode
\begin{tikzpicture}[x=1pt,y=1pt]
\definecolor{fillColor}{RGB}{255,255,255}
\path[use as bounding box,fill=fillColor,fill opacity=0.00] (0,0) rectangle (415.55,216.81);
\begin{scope}
\path[clip] ( 37.20, 61.20) rectangle (378.35,167.61);
\definecolor{drawColor}{RGB}{190,190,190}    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.84, 65.14) -- (158.52,102.93);    

...

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  0.80] at ( 40.80,125.88) {22};
\end{scope}
\begin{scope}
\path[clip] ( 37.20, 61.20) rectangle (378.35,167.61);
\definecolor{drawColor}{RGB}{0,0,0}    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (257.47, 63.30) { 60};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (273.00, 68.70) { 80};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (288.53, 74.10) {100};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (304.05, 79.50) {120};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (319.58, 84.90) {140};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (335.11, 90.30) {160};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (350.63, 95.70) {180};    

\node[text=drawColor,anchor=base west,inner sep=0pt, outer sep=0pt, scale=  0.80] at (366.16,101.10) {200};    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.84, 65.14) --
    (245.47, 65.14);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (415.55,216.81);
\definecolor{drawColor}{RGB}{0,0,0}    

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (147.65, 33.60) {Breite in mm};
\end{scope}
\begin{scope}
\path[clip] ( 37.20, 61.20) rectangle (378.35,167.61);
\definecolor{drawColor}{RGB}{0,0,0}    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (245.47, 65.14) --
    (354.16,102.93);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (415.55,216.81);
\definecolor{drawColor}{RGB}{0,0,0}    

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (393.95,102.93) {Länge in mm};
\end{scope}
\begin{scope}
\path[clip] ( 37.20, 61.20) rectangle (378.35,167.61);
\definecolor{drawColor}{RGB}{0,0,0}    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.84, 65.14) --
    ( 49.84,125.88);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (415.55,216.81);
\definecolor{drawColor}{RGB}{0,0,0}    

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 16.80, 95.51) {Dicke in mm};
\end{scope}
\begin{scope}
\path[clip] ( 37.20, 61.20) rectangle (378.35,167.61);
\definecolor{drawColor}{RGB}{0,0,0}    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (158.52,102.93) --
    (354.16,102.93);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (158.52,163.67) --
    (354.16,163.67);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.84, 65.14) --
    (158.52,102.93);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.84,125.88) --
    (158.52,163.67);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (158.52,102.93) --
    (158.52,163.67);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (354.16,102.93) --
    (354.16,163.67);
\definecolor{drawColor}{RGB}{139,26,26}    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (235.83,152.12) -- (235.83,101.10);    

...

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (108.53, 80.93) -- (108.53, 70.00);    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (141.82, 98.78) -- (141.82, 69.62);
\definecolor{drawColor}{RGB}{139,26,26}    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] ( 97.69, 80.66) -- ( 97.69, 66.09);
\definecolor{drawColor}{RGB}{16,78,139}    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (108.68, 87.55) -- (108.68, 65.68);
\definecolor{drawColor}{RGB}{139,26,26}    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (101.69, 83.90) -- (101.69, 65.68);
\definecolor{drawColor}{RGB}{16,78,139}    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (109.57, 74.71) -- (109.57, 65.60);    

\path[draw=drawColor,line width= 0.4pt,dash pattern=on 1pt off 3pt ,line join=round,line cap=round] (109.57, 86.86) -- (109.57, 65.60);
\definecolor{fillColor}{RGB}{139,26,26}    

\path[fill=fillColor] (235.83,152.12) circle (  2.25);    

...

\path[fill=fillColor] (121.72,106.17) circle (  2.25);    

\path[fill=fillColor] (121.03,107.39) circle (  2.25);
\definecolor{fillColor}{RGB}{139,26,26}    

\path[fill=fillColor] (115.02, 85.40) circle (  2.25);    

\path[fill=fillColor] (117.81, 85.40) circle (  2.25);
\definecolor{fillColor}{RGB}{16,78,139}    

\path[fill=fillColor] (118.93, 87.83) circle (  2.25);    

\path[fill=fillColor] (108.34, 82.23) circle (  2.25);    

\path[fill=fillColor] (108.53, 80.93) circle (  2.25);    

\path[fill=fillColor] (141.82, 98.78) circle (  2.25);
\definecolor{fillColor}{RGB}{139,26,26}    

\path[fill=fillColor] ( 97.69, 80.66) circle (  2.25);
\definecolor{fillColor}{RGB}{16,78,139}    

\path[fill=fillColor] (108.68, 87.55) circle (  2.25);
\definecolor{fillColor}{RGB}{139,26,26}    

\path[fill=fillColor] (101.69, 83.90) circle (  2.25);
\definecolor{fillColor}{RGB}{16,78,139}    

\path[fill=fillColor] (109.57, 74.71) circle (  2.25);    

\path[fill=fillColor] (109.57, 86.86) circle (  2.25);
\definecolor{drawColor}{RGB}{0,0,0}    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.84,125.88) --
    (245.47,125.88);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (245.47,125.88) --
    (354.16,163.67);    

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (245.47, 65.14) --
    (245.47,125.88);
\end{scope}
\end{tikzpicture}

다른 라텍스 파일에 포함되어 있습니다:

\begin{figure}
    \centering
    {\input{graphics/dataBrakePads}}
    \caption{Systematisierung der Funktionen und Einflüsse auf die Entwicklung des Klassifizierungssystems}
    \label{fig:dataBrakePads}
\end{figure}

내 질문에 대해 생각해 주셔서 감사합니다.

답변1

공백은 TikZ 코드 전체에 흩어져 있는 몇 가지 다른 줄에서 나옵니다. 우선, 두 번째 줄은 다음과 같습니다.

\path[use as bounding box,fill=fillColor,fill opacity=0.00] (0,0) rectangle (415.55,216.81);

use as bounding box는 정확히 말하는 것을 의미합니다. 즉, 의 경계 상자가 해당 경로, 즉 및 tikzpicture에 모서리가 있는 직사각형에 의해 정의된다는 것입니다 .(0,0)(415.55,216.81)

또한 로 시작하는 여러 줄이 있으며 \path[clip]그 중 일부는 경계 상자에 영향을 미칩니다. 특히, 다음과 같은 두 줄(표시한 TikZ 코드의 53 및 66)이 있습니다.

\path[clip] (  0.00,  0.00) rectangle (415.55,216.81);

길은 길 clip과 달리 use as bounding box바깥에 있는 모든 것을 차단합니다. 하지만 클리핑이 필요한 것 같지는 않으므로 모든 클리핑을 주석 처리할 수 있습니다. 클리핑이 필요한 경우 직사각형의 크기를 조정하세요.

코드 출력

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\begin{document}
This is what your original code looks like:
\medskip

\fbox{\input{fig}}

\bigskip

And this is with all \verb|\path[clip]| and the \verb|\path[use as bounding box, ...]| commented out:
\medskip

\fbox{\input{fig2}}
\end{document}

관련 정보