Reputation: 2183
I'm using knitr to compile my thesis, and for this ggplot I'm using manual shapes (to be consistent with another plot I'm copying). The problem is, one of the shapes I want to use is a percent symbol and I can't figure how to do it given it's special status in Latex.
Here's a minimal working example:
\documentclass[10pt, a4paper]{article}
%\newcommand{\pct}{\%}
\begin{document}
<<packages>>=
library(ggplot2)
@
<<data>>=
x=rnorm(10,1,2)
y=rnorm(10,1,2)
context=letters[1:5]
data=cbind.data.frame(x,y,context)
@
<<plot>>=
ggplot(data,aes(x,y,shape=context))+
geom_point(size=6)+
scale_shape_manual(values=c("V","Percent","?","@","#"))
@
\end{document}
Giving:
So I'm just writing `Percent' for now instead of the symbol.
As you can see in the second line, I've tried to mess about with making a new command \pct but it doesn't work. Any suggestions would be appreciated. I could just use another symbol, but I want it to be the same as the plot I'm replicating, ideally.
Upvotes: 2
Views: 654
Reputation: 22516
When I tried it with Knitr, R Markdown as well as R Sweave (from inside RStudio) it rendered the %
signs without any troubles. I am not doing anything special, just quoting the % sign.
Here's my Rnw file in its entirety:
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<packages>>=
library(ggplot2)
@
<<Plot, fig=TRUE>>=
ggplot(mtcars,aes(gear,hp,shape=factor(carb)))+geom_point(size=6) +
scale_shape_manual(values=c("V","%","?","@","#", "3"))
@
\end{document}
Which gives me the document with the percentage signs. At least in my case, the %'s special meaning seems to get escaped.
Upvotes: 1