ggplot2 and tikzDevice

780 views
Skip to first unread message

Sandy Small

unread,
Aug 18, 2011, 7:43:54 AM8/18/11
to ggplot2
Hi
Can anyone give me a reliable example of how to use gglot2 with
tikzDevice.

I want to produce consistent plots (of 4 possible different sizes)
with consistently readable fonts in my PhD thesis and like the output
from ggplot2. I have been scaling (in latex) EPS output from ggsave
but this only produces sensibly sized fonts in my larger figure sizes.
If I can get tikzDevice to work with ggplot2 I would guess that offers
the best option.

Alternatively I can save each image at the required size and not scale
in latex which I think will keep the font readable. Can anyone
confirm?

Many thanks
Sandy

Stu Sharples

unread,
Aug 18, 2011, 8:25:26 AM8/18/11
to Sandy Small, ggplot2
I think I understand your problem. I recently ran in to a similar dilemma when trying to work out how to best produce plots for an A0 poster.

I found the best thing to do was to avoid scaling and just try to produce the plots at the needed size. So I first calculate (in mm or inches) how big I actually wanted the plot to be, and use ggsave to save it at the appropriate dimensions. But I also set the font size for the tick and axis labels by changing the 'base_size' of the theme, for example:

 

require(ggplot2)
data(diamonds)

p1 <- qplot(x = carat, y = price, data = diamonds) +
  theme_bw(base_size = 24)
  # set font size to 24pt which is fairly large

ggsave(p1, file = "p1.pdf", width = 11, height = 11)
  # width and height of 11 inches is fairly big



Overall, it produces the plot at the right size with the right formatting, no need for scaling, or any guess work for that matter.

Cheers

Stu



--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Ista Zahn

unread,
Aug 18, 2011, 9:53:06 AM8/18/11
to Sandy Small, ggplot2
Hi Sandy,
If you use pgfSweave this should all be handled automatically (see the
pgfSweave vignettes for examples). If you want to create the figures
separately, just use tikz() in R and \input{} in the LaTeX file. For
example:

In R:
tikz(file = "Figure1.tex")
print(ggplot(mtcars, aes(x = hp, y = mpg)) + geom_point())
dev.off()

in LaTeX:
\input{Figure1.tex}

In other words, it should just work.

Best,
Ista

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Reply all
Reply to author
Forward
0 new messages