One of the confusing things about R for newcomers is the graphics system. Or rather, systems: there are three major ways of creating a graph in R. There's the base graphics system, which was adopted from S and has been in R from the beginning, and is documented in the Introduction to R manual. But all the cool R programmers these days use one of the newfangled modern systems: either lattice or ggplot2 (both of which are built on the "grid" graphics subsystem).
I'm often asked which of these are better to use, and it's a hard question to answer. Lattice is probably easier to learn, but once you get over the learning curve ggplot2 has a lot of elegance and power.
To help you decide, the awesome blog Learning R is working through Deepayan Sarkar's book Lattice: Multivariate Graphics with R and is reproducing the graphics therein using ggplot2. This side-by-side comparison of the same graph done in the two packages is a great way to get a sense of the similarities and differences between the two methods, and to help decide which package is right for you. Be sure to check out all the parts in this multi-part series.
Learning R: ggplot2 Version of Figures in “Lattice: Multivariate Data Visualization with R” (Part 1) (Part 2) (Part 3)
Hi,
Thanks for the post and links. The "Learning R" blog is great indeed and worth recommending.
I was curious why do you think 'lattice' is easier to learn than, say, base graphics?
I mostly use base system. I use lattice mainly for making fancy conditioning plots (a la 'coplot'). I remember that to be able to pass some arguments to low-level point-within-panel-drawing function these had to take the form of nested lists... Which was pretty unintuitive for me.
~michal
Posted by: michal | July 09, 2009 at 08:13
I would say that lattice is quite difficult to learn too, but very powerful and I much prefer it to ggplot. ggplot is great, but I haven't yet found a reason to use it instead of lattice.
Posted by: anon | July 09, 2009 at 11:05
I agree that the post comparing the two systems is really very good. It probably will provide the most useful information around on these two systems by the end of it.
I would also agree that lattice is not easier to learn, but it (currently) has some advantages over ggplot. One significant one is speed; another is finer control over settings. However, one aspect I really like about ggplot is altering colour/shape/lwd etc. by value in the data, which can be hard going in lattice.
It will be interesting to see how the comparisons will stand up later on in Deepayan's book where finer control and surfaces are considered...it would also be useful if 'learnr' provides some thoughts on the good/bad at the end of it.
BTW - the Revolutions blog is excellent.
David
Posted by: David | July 09, 2009 at 12:35
This looks fantastic. I'm pumped!
Too bad I already spent so much time looking at help(par)...
But oh well, I guess that's the way computer systems work, always improving.
Posted by: stat arb | November 01, 2010 at 19:16