私はknitrのいくつかの動作に少し困っています。実際の例では 4 つのプロットが表示され、2 つの異なるプロット方法を使用してすべて同じデータが表示されます。
前文:
\documentclass{article}
最初の 2 つのプロットは、R ベースの plot コマンドを使用して作成されます。
<<one.one,fig.width=4,fig.height=3,fil.align='center',fig.show='asis'>>=
par(mar=c(4,4,1,1),mgp=c(2,1,0),cex=0.8)
plot(cars,pch=20,col='darkgray')
@
<<one.two,fig.width=4,fig.height=3,fil.align='center',fig.show='asis'>>=
par(mar=c(4,4,1,1),mgp=c(2,1,0),cex=0.8)
plot(cars,pch=18,col='darkgray')
@
出力は(削除された)によって与えられます:
ggplot2 を使用した同じプロットのコード例は次のとおりです。
<<two.one,fig.width=4,fig.height=3,fil.align='center',fig.show='asis'>>=
library(ggplot2)
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red')
test3
@
<<two.two,fig.width=4,fig.height=3,fil.align='center',fig.show='asis'>>=
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red',shape=3)
test3
@
そして、出力は(削除されています):
tikzDevice を使用しても問題は解決しません。この問題は、少なくとも私が覚えている限り、昨年の 11 月から存在しています。Yihui Xie の本を読んで解決しようとしましたが、彼のウェブサイトの例を使用しましたが、失敗しました。
だから:誰かが同じ問題を見て、それに対する解決策を思いつきましたか? 特定の方向を指し示すヒントでも役立つ場合があります。
私のシステム:
Win 7、MikTeX2.9 (2016 年 1 月 15 日に更新されたパッケージ)、TeXstudio 2.10.6、R3.2.2 (2016 年 1 月 15 日に更新されたパッケージ)。
編集:
CL からの依頼で、R とパッケージもすぐに更新しました。下に私の MWE があります。pch=20 を使用するとデータ ポイントが表示されない問題。pch=19、geom_point() は、明示的にグラフィック デバイスを選択しない限り永続的です。tikzDeviceを使用してプロットを *.tex に保存すると、データ ポイントが表示されます。また、dev='tikz' をチャンク オプションに入れると表示されます。他のグラフィック デバイスも同様に動作するようです。
MWE は次のとおりです。
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{verbatim}
this chunk options:
fig.width=4,fig.height=3,fig.align='center',fig.show='asis'
\end{verbatim}
<<one.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis'>>=
library(knitr)
par(mar=c(4,4,1,1),mgp=c(2,1,0),cex=0.8)
plot(cars,pch=20,col='darkgray')
fit<-lm(dist~speed, data=cars)
abline(fit,lwd=1,col='red')
par(mar=c(4,4,1,1),mgp=c(2,1,0),cex=0.8)
plot(cars,pch=18,col='darkgray')
fit<-lm(dist~speed, data=cars)
abline(fit,lwd=1,col='red')
library(ggplot2)
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red')
test3
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red',shape=3)
test3
@
\begin{verbatim}
next chunk options:
three.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis'
\end{verbatim}
<<three.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis'>>=
require(tikzDevice)
tikz("three.one.tex",width=4.2,height=3)
plot(cars,pch=20,col='darkgray')
fit<-lm(dist~speed, data=cars)
abline(fit,lwd=1,col='red')
dev.off()
tikz("four.one.tex",width=4.2,height=3)
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red')
test3
dev.off()
@
\input{three.one.tex}
\input{four.one.tex}
\begin{verbatim}
next chunk options:
five.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis, dev='tikz'
\end{verbatim}
<<five.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis',dev='tikz'>>=
plot(cars,pch=20,col='darkgray')
abline(fit,lwd=1,col='red')
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red')
test3
@
\begin{verbatim}
next chunk options:
five.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis, dev=c('png','pdf')
\end{verbatim}
<<seven.one,fig.width=4,fig.height=3,fig.align='center',fig.show='asis',dev=c('png', 'pdf')>>=
plot(cars,pch=20,col='darkgray')
abline(fit,lwd=1,col='red')
test1<-ggplot(cars,aes(x=speed,y=dist))
test2<-test1+geom_smooth(method="lm",se=FALSE,color='red',data=fit)
test3<-test2+
ggtitle("") +
geom_point(size=1,colour='red')
test3
@
\end{document}
その問題が再現できない場合は、それで和解し、無視します。しかし、それが再現可能であれば、解決策がどのように見えるか興味があります.
テストに加えて、私は別の問題を思いつきました。その問題は、少なくとも 1 人の他の TeX ユーザーによっても述べられていることがわかりました。Knitr と LaTeX パッケージ xcolor は、すべての友人の中で最高ではないようです。
再度、感謝します。