r - knitr plots: Points (geom_point(), pch=20, pch=19...) not showing -


i'm bit troubled behaviour of knitr. working example should show 4 plots, showing same data using 2 different plot-methods.

preamble:

\documentclass{article} 

the first 2 plots made using plot command of r-base:

<<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') @ 

the outputs given (deleted):

for same plot ggplot2 code examples are:

<<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 @ 

and outputs (deleted):

even using tikzdevice doesn't solve issue me. problem exists me since nov. last year, @ least far can remember. tried solving reading yihui xie's book, used examples website, failed.

so: has seen same problem , has come solution it? hint pointing in direction might help.

my system:

win 7, miktex2.9 (packages updated on 15.01.2016), texstudio 2.10.6, r3.2.2 (packages updated on 15.01.2016).


edit:

as asked cl, updated r , packages right along, too. below find mwe. problem of not-showing data points when using pch=20 ; pch=19, geom_point() persistent long don't choose graphics device explictly. when using tikzdevice , saving plots *.tex, data points show. show when putting dev='tikz' chunk options. other graphic devices seem work well.

the mwe is:

\documentclass{article} \usepackage{graphicx} \usepackage{tikz} \begin{document}  \begin{verbatim} 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} 

if issue not reproducible, make peace , ignore it. if it's reproducible, i'm curious solution might like.

along tests, came issue , found problem stated @ least 1 other tex-user, too: knitr , latex package xcolor don't seem best of friends.

thank's again.

knitr vs. xcolor


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -