
아래와 같은 이미지를 자동으로 생성하는 방법을 찾고 있습니다.
현재로서는 이 이미지(SPSS에 의해 생성된 것으로 생각되지만 해당 부분과 아무 관련이 없습니다.)가 있기 때문에 MWE가 없습니다. 물론 이 이미지를 내 문서에 추가할 수도 있지만 이러한 문제는 "네이티브" LaTeX 방식을 시도해보고 싶은 빈도로 발생합니다. 나는 일부 그래픽 패키지가 작업에 달려 있다고 확신하지만 어디서부터 살펴봐야 할지조차 모릅니다.
나는 당신이 나를 위해 일을 해주기를 기대하지 않습니다. 그래서 내가 요구하는 것은 올바른 방향을 알려주는 지침, FAQ, HOWTO, 아마도 샘플뿐입니다.
답변1
이는 완전한 답변이 아니며 데이터의 자동화된 처리가 필요하지 않다고 가정하는 포인터일 뿐입니다.
편집: Jake가 권장한 대로 \addplot table
대신 사용하면 \addplot plot coordinates
많은 번거로움이 줄어듭니다.
\documentclass{book}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\definecolor{mybarcolor}{RGB}{210 207 155}
\pgfmathsetmacro{\xmin}{-.5}
\begin{axis}[ymin=0,%
xmin=\xmin,%
xtick={0,2,4,6},%
xticklabels={.00,2.00,4.00,6.00},%
axis background/.style={fill=black!10},%
ylabel=\textbf{H\"{a}ufigkeit},%
xlabel=$D_\mathrm{rel}$,%
]
\addplot[ybar interval,fill=mybarcolor] table {%
0 7
.5 38
1 23
1.5 8
2 8
2.5 8
3 2
3.5 1
4 2
4.5 0
5 0
5.5 1
6 1
};
\addplot[domain=\xmin:6,samples=100] {18*exp(-.5*(x-1.5)^2)};
\end{axis}
\end{tikzpicture}
\end{document}
답변2
다음은 Asymptote 매뉴얼에서 약간 수정된 예입니다. 통계 데이터로부터 이미지를 자동으로 생성할 뿐만 아니라 처음에 데이터를 생성하는 방법도 보여줍니다. 다음 hist.asy
파일 을 asy -f pdf hist.asy
.
import graph;
import stats;
size(400,200,IgnoreAspect);
real lineWidth=2pt;
pen histFillPen=rgb(217/255, 206/255, 143/255)+opacity(0.7);
pen histLinePen=black;
pen linePen=red+lineWidth;
pen bgPen=rgb(241/255, 240/255, 238/255);
int n=10000;
real[] a=new real[n];
for(int i=0; i < n; ++i) a[i]=Gaussrand();
path g=graph(Gaussian,min(a),max(a));
pair gMin=min(g);
pair gMax=max(g)+(0,0.05);
filldraw(box(gMin,gMax),bgPen,black);
draw(g,linePen);
// Optionally calculate "optimal" number of bins a la Shimazaki and Shinomoto.
int N=bins(a);
histogram(a,min(a),max(a),N,normalize=true,low=0,fillpen=histFillPen,drawpen=histLinePen,bars=true);
xaxis("$x$",BottomTop,RightTicks);
yaxis("$dP/dx$",LeftRight,RightTicks(trailingzero));
답변3
다른 도구를 사용하여 플롯을 PDF로 생성하고 이를 TeX에 포함시키려는 경우 반드시 gnuplot을 제안하겠습니다. 그것은 매우 강력하며 원하는 것을 가상으로 그래프로 표시할 수 있습니다. 플롯을 자동으로 생성하려면 LaTeX Makefile 또는 시퀀스에 gnuplot 명령을 포함해야 합니다. 여러 데이터파일에서 여러 개의 유사한 플롯을 생성하려는 경우 데이터파일을 매개변수화할 수도 있습니다.
답변4
통계 데이터에서 자동으로 생성된 이미지(및 텍스트 결과)로 LateX 문서를 만드는 것이 작업이라고 생각합니다.아르 자형~와 함께짜다또는뜨개질을 하는 사람.
간단히 말해서, R 코드의 "청크"가 삽입된 (noweb 파일) .Rnw
대신 확장자를 갖는 일반 LateX 문서를 만들 수 있습니다 . .tex
그런 다음 R의 Sweave는 이를 실제 .tex
파일로 내보냅니다. 여기서 R 청크는 이러한 R 청크에 의해 생성된 결과(이미지, 테이블 또는 텍스트)와 함께 LateX 코드에 의해 변경됩니다. 그런 다음 평소와 같이 .tex
파일을 컴파일할 수 있습니다 .pdflatex
예를 들어 test.Rnw
최소 R 청크가 포함된 최소 파일은 다음과 같습니다.
\documentclass{article}
\begin{document}
<<>>=
2+3
@
\end{document}
.tex
확장자를 포함하고 컴파일된 위 파일은 pdflatex
다음과 같이 간단하게 생성됩니다.
<<>>= 2+3 @
그러나 R CMD Sweave test.Rnw
당신과 함께 개종하면 다음과 같은 것을 얻게 될 것입니다 test.tex
:
\documentclass{article}
\usepackage{Sweave}
\begin{document}
\begin{Schunk}
\begin{Sinput}
> 2+3
\end{Sinput}
\begin{Soutput}
[1] 5
\end{Soutput}
\end{Schunk}
(를 사용하여) 컴파일하면 다음 pdflatex test.tex
이 생성됩니다.
> 2+3
[1] 5
그다지 인상적이지는 않습니다. R 콘솔에서 볼 수 있는 것처럼 간단한 합계만 표시하면 됩니다. 그러나 R은 환상적인 통계 프로그램이며 R 청크의 결과는 입력을 표시하거나 표시하지 않고 \includegraphics{}
멋진 그래프가 있거나 완전한 LaTeX 테이블 부동 소수점( )이 될 수 있습니다. \begin{table} ...
단순한 숫자인 결과라도 텍스트에 연결될 수 있습니다 \Sexpr
(예: \Sexpr{2+3}
}. 따라서 예를 들어 정기적인 통계 LaTeX 보고서를 생성하려면 R에서 관리하는 원본 데이터( .csv
예: 간단한 파일)만 두 개의 명령 또는 간단한 명령을 사용하여 수정합니다. 스크립트를 사용하면 자동으로 업데이트된 그래프를 얻을 수 있을 뿐만 아니라 업데이트된 테이블과 업데이트된 결과도 매번 LaTeX 코드를 편집하지 않고 R을 열지 않고도 얻을 수 있습니다. 이제 충분히 인상적입니다.
위의 화면 캡처는 보다 정교한 hist.Rnw
파일을 사용하여 생성되었습니다.
% File: hist.Rnw
%
% Usage:
%
% R CMD Sweave hist.Rnw
% pdflatex hist.tex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\begin{document}
\lipsum[1] % dummy text
\begin{figure}[h]
\centering
% R Chunk
<<Histogran,echo=F,fig=T>>=
# Some random data
foo <- rnorm(1000, mean=1, sd=1)
# The histogram
hist(foo, prob=TRUE, border="tan4", ylab="Häufigkeit",
xlab="D_rel",col=rainbow(25,start=.4,end=.35), main="")
# To have also the ugly background area (optional):
rect(par("usr")[1], par("usr")[3], par("usr")[2], par("usr")[4],
col = "lightgrey")
hist(foo, prob=TRUE, border="tan4", ylab="Häufigkeit",
xlab="D_rel",col=rainbow(40,start=.1,end=.4), main="", add=T)
# Density plot
curve(dnorm(x, mean=mean(foo), sd=sd(foo)),
lwd=2, col="darkred", add=T)
@ % end of R chunk
\caption{This is a histogram of foo population with
mean=\Sexpr{round(mean(foo),2)} and sd=\Sexpr{round(sd(foo),2)}.
On the other hand, significance of Shapiro-Wilk test of normality is
p=\Sexpr{signif(shapiro.test(foo)$p.value,2)}, so this is a normal
population as sure as 2+2=\Sexpr{2+2}, as everybody knows (except some
processors with floating point bugs). }
\end{figure}
\lipsum[3] % more dummy text
\end{document}