[Tex/LaTex] Using geom_segment dashed line has odd behavior when using tikz device

knitrtikz-pgf

My example is:

\documentclass[12pt]{article}
\begin{document}
<<eg, dev='tikz', size='normalsize', echo=FALSE, message=FALSE, warning=FALSE, sanitize=TRUE>>=
require(ggplot2)
p1 <- ggplot() + geom_segment(aes(x = 1, y = 1, xend = 2, yend = 2),
                              linetype= 2)
p1
@
\end{document} 

Which generates a dashed line (when using other graphics devices). When using tikz, there is a thin black line sitting underneath the dashed line. Any ideas as to how to get rid of this?

Best Answer

I have worked out a patch solution for this. Use geom_path to replace the misbehaving geoms. e.g.

    p1 + geom_path(data=data.frame(x=c(1, 2),
                          y=c(1, 2)),
          aes(x=x, y=y), linetype=2)
Related Question