Search code examples
rsweave

Inverted Question(¿) in Sweave/tikZ Generated R Plot


I am relatively new to Sweave, and R in general and have been having issues trying to render basic math symbols in my plot labels. I believe the problem may be cause by either Sweave or tikzDevice package as I am able to render the math symbols perfectly fine if I use either a png or pdf device.

Writing this code to either a png or pdf device gives expected output --the > symbol

qplot(factor(cyl), data=mtcars, geom="bar", colour=factor(cyl)) + scale_x_discrete(paste("",">","6k"))

Using .tex output file resulting from running Sweave on file below replaces > symbol with ¿ symbol

<<fig=FALSE, echo=FALSE>>=
require(tikzDevice)
require(ggplot2)
require(reshape2)
tikz('sweave-math-symbols.tex', width=5.9, height=2.7)

qplot(factor(cyl), data=mtcars, geom="bar", colour=factor(cyl)) + scale_x_discrete(paste("",">","6k"))
@

LaTeX document that uses output file from Sweave is below

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

%opening
\title{Sweave Math Symbols}
\author{Phiri}

    \begin{document}

    \maketitle

    \begin{abstract}

    \end{abstract}

    \section{Illustration}
    \input{sweave-math-symbols.tex}

    \end{document}

Where is this problem stemming from and how do I go about fixing it?


Solution

  • Your Sweave file worked for me without modification (on Ubuntu 10.04), but you might try wrapping the > in TeX math delimiters ($$, i.e. $>$); frankly, I'm surprised that /don't understand why it works OK without the delimiters in some contexts.