

An Introduction on How to Make Beautiful Charts with R and ggplot2 - minimaxir
http://minimaxir.com/2015/02/ggplot-tutorial/

======
barik
Like many ggplot articles, they seem to consider the primary output being the
Web, and not print publications.

One thing I haven't quite figured out with ggplot2 is how to keep the text
size constant in publications across figures. If you look at professionally
typeset books, you'll see that the figure text (say the labels in a chart) is
the same as the text of the article itself. Even this article suffers from the
problem (but obviously, that's because the text is in a PNG so it can't scale
with the article text).

The only workaround I have is to manually set the width of the figure before
exporting, but this is fairly inflexible. Perhaps tikz output is another
option, but my understanding (possibly incorrect) is that it isn't maintained
anymore.

Can anyone recommend a good workflow for charts in R and ggplot2 to handle
this situation?

------
leni536
These are really nice plots for the web. For publication it's quite essential
for me to produce pdf charts with the text rendered with LaTeX. I use python's
matplotlib for that. Can ggplot do something like this? That would be really
nice.

~~~
ArnoVanLumig
You can do it with ggplot2 using the 'extrafont' library and installing the CM
fonts (after loading extrafont, do 'font_install("fontcm")'). Then it's just
adding

    
    
      + theme(text=element_text(family="CM Roman"))
    

to your plot.

For me that doesn't work when displaying the graphs in a window, but it does
work when exporting to PDF with ggsave. Afterwards you have to embed the CM
font into the PDF with 'embed_fonts'.

------
dewarrn1
ggplot2 is a very elegant language for describing how to draw your data. Two
great books for interested parties: the R Graphics Cookbook [0] which has tons
of ggplot2 examples and gets you plotting immediately; and ggplot2: Elegant
Graphics for Data Analysis [1] written by the author of the ggplot2 library
and providing a very thorough description of this implementation of the
"Grammar of Graphics".

[0] [http://amzn.to/1AhyEdE](http://amzn.to/1AhyEdE)

[1] [http://amzn.to/1B4OSq9](http://amzn.to/1B4OSq9)

------
remarkEon
This is great. I started learning R really just to become more effective at
winning arguments about baseball and it's such a great tool (also for things
other than baseball arguments).

------
acomjean
ggplot2 is great. I recently took this intro to ggplot2. A lot of the
biologists in my lab go to my officemate for his R/ggplot2 plotting skills, to
help create graphs for papers.

R takes a little getting used to but making graphs programmatically is pretty
awesome.

The class materials and downloads. The wrap-up section has additional links:

[http://tutorials.iq.harvard.edu/R/Rgraphics/Rgraphics.html](http://tutorials.iq.harvard.edu/R/Rgraphics/Rgraphics.html)

~~~
johnchristopher
I am going off-topic but I have a question for you.

I recently had a discussion with a friend of mine who's into academics (2nd
PhD). He's highly proficient in LaTeX/Perl/R and typeset his own papers (for
publishing and for conferences) but he mentioned that researchers shouldn't do
that because this is too much time consuming and it could be better done by
someone trained for that: a secretary. But budget cuts ended up forcing
researchers, who can hardly type with one finger (and aren't trained to use
LaTex/R/etc.) , to type out their papers.

Wouldn't it be better if researchers could just send a rough draft to a
service that would typeset and make beautiful plots out of it ? Isn't your
officemate (may I assume he is a researcher too ?) running the risk to spend
too much time on formating papers (and God knows you can spend a lot of time
in LaTeX and R docs) ?

~~~
acomjean
My office is lab IT/ bioinformatics staff not researchers.

I think most people at this point type better than they write, also I think
they compose while they write, making edits etc. Plus errors in
transcriptions. I haven't seen anyone doing much formatting/ typesetting of
the text, which you are right, could be done by anyone.

------
tariqr
Great, I was introduced to ggplot2 via your note in the footer in articles
you've shared in the past. This helps a great deal. Thanks Max! :)

ps: Is there a way to generate vector outputs?

~~~
minimaxir
ggsave (and most R graphics devices) supports .pdf and .svg output. I remember
reading an article about prerendering plots in ggplot2 then exporting into
Illustrator for more professional touch ups.

Note that if you want to include custom fonts with those outputs, it gets
_really_ complicated.

~~~
hudibras
Here's a couple articles on touch-ups that I've hoarded. (Thanks, Pinboard!)

[http://www.vikparuchuri.com/blog/making-infographics-
using-r...](http://www.vikparuchuri.com/blog/making-infographics-using-r-and-
inkscape/)

[http://rforwork.info/2012/04/12/fun-editing-r-graphs-in-
inks...](http://rforwork.info/2012/04/12/fun-editing-r-graphs-in-inkscape/)

~~~
dewarrn1
Decent references. I find myself doing similar, final-draft touch-ups with
plots for manuscripts.

------
wodenokoto
How are things progressing with ggplot for python? I am quite jealous of the
syntax

~~~
dewarrn1
ggplot for Python [0] is coming along nicely. My own recent use suggests that
for basic plotting, most of the expected functionality is there. More advanced
displays, such as faceting, are still in progress. Overall, I've been
impressed.

[0] [https://github.com/yhat/ggplot/](https://github.com/yhat/ggplot/)

