Lattice or GGplot2

ggplot2
lattice

#1

I was searching for differences in both the packages but most of the articles that I found online were just very old. LIke some of them were 8 to 10 years old.

Is there anybody who still uses lattice. Is it actually a package worth learning and what are the places it can actually help.

Please do reply if you use Lattice or have used lattice. I am just curious to know.


#2

People definitely still use both packages.
You can visually see some of the differences in Tufte in R:
http://motioninsocial.com/tufte/

Here's another post: Plotting in R: Intro to base, lattice and ggplot2 by Joseph V. Casillas
http://www.jvcasillas.com/base_lattice_ggplot/

And another side-by-side comparison from STAT545, below:
https://www.stat.ubc.ca/~jenny/STAT545A/block18_gapminderGgplot2VsLattice.html


#3

I think Hadley himself said he developed ggplot after being very knowledgeable about lattice but becoming frustrated about its ease of use.

They are both based on grid and thus very s8imilar plots may be produced with both, but I found the default plots in lattice unsatisfactory when starting out. I found no reason to return once I had learned ggplot2.


#4

Thanks for such a great article to read. I would definately read it. Thanks for the help.


#5

Thanks for replying so quick @martin.R. Thanks a lot. But I wanted to add.

Hadley got frustrated with the lattice of 2005. It's 2017. :grinning: :grinning: :grinning::grinning: :grinning:

I wanted to know some if there are any places where it could be useful. Because i think in caret the basic plot produced are from lattice. I think so I am not sure but that's what I wanted to know if there are any places where it could be useful.


#6

caret is on github, so you can see exactly what is used. Short story - both ggplot and lattice are used for different things.
ggplot example
lattice example


#7

Thanks but My question is exactly what different things are those where I could use lattice.

:grinning::grinning::grinning::grinning::grinning::grinning:


#8

I think this is something best accomplished by playing around with both, and comparing your experiences with the two. Or, as with a couple of those initial links, just looking at the differences. I'd also encourage you to look at some of the comparison posts, even if they aren't very new. Both packages are sufficiently "mature" that they won't have changed too wildly in the past couple of years (and, especially if on stack overflow, people tend to comment if there have been changes).


#9

Thanks @mara

I do not want to learn an entirely different library. Just for something I already have learned like plotly, ggplot and many more...

I was trying to see if there is any lattice user available and can be tell me why does he still uses it.

Simple. I like your articles though I will surely read them after I reach home..


#10

The reason people mainly give for using lattice is that they learned it first a long time ago and do not want to migrate. Some prefer the lattice syntax as ggplot2 is verbose.


#11

the learnr blog had a detailed comparison around 2009, I suspect many of the comments are still valid. Note that latticeExtra brought some features of ggplot2 to lattice, such as a +layer() syntax.


#12

My guess is that you will find very few people writing large quantities of new code using lattice and few people who choose lattice when deciding which non-base vis package to learn.

I say this as someone who has gone through long periods of hard-earned proficiency in base then lattice then ggplot2. I have also taught a a great deal with all 3 approaches. I see no reason to pick up lattice at this point.


#13

I basically agree with Jenny, but since the OP wanted a list of pros/cons, here are some

advantage lattice: formula interface makes the code for lattice plots look a lot like the code used to create models with lm() and friends, simple plots are simpler to make and the code is terser, theming includes data elements and not just non-data elements

advantage ggplot2: better overall design that makes it easier to build up complex plots from modular elements, aesthetics for shape and size seem like a better idea than the "groups" idea of lattice, most people like the default look of ggplot2 plots better, now that it is relatively easy to create new stats and geoms I prefer to extend ggplot2 than to write panel and pre-panel functions for lattice

For quite a number of years, the advantages of lattice made it the package of choice for me when teaching beginners (using the mosaic package as well so that numerical summaries could also be done with same formula interface). At the same time, I did most of my own stuff in ggplot2, and when students outgrew the sweet spot of lattice, I helped them migrate to ggplot2.

Last summer Danny Kaplan and I introduced ggformula -- a formula interface to ggplot2 graphics. We created it with newbies in mind, but I'm finding that I now do almost all of my plotting with ggformula. I've heard the same from others who began using ggformula with students and migrated their own work to ggformula as well.

The biggest downside to ggformula is that it is the new kid on the block, and primarily provides a different interface to ggplot2, you don't get major new functionality -- just a different path to what ggplot2 can do. (To be fair, ggformula does add a few functions that make certain tasks easier to do than would be the case in ggplot2.)


#14

I also agree with Jenny. I started learning lattice shortly after I started using R about ten years ago. But when I learned of ggplot2, I tried it and found it to be more consistent and intuitive. I was curious how much activity there is on the lattice and ggplot2 tags on StackOverflow. Here's a (ggplot2) graph of the monthly number of questions for each tag, based on data from the Stack Exchange data explorer.


#15

Thanks everybody for taking time and repying me.

My takeaway here is lattice used to be a very good package over base R plotting system but GGplot2 is much better and no body now uses Lattice except some people who already have learned it years ago.

I being a ggplot2 user have no need to learn lattice.

Thanks for giving me links specially the Tufte one. I highly appreciate your responses.


#16

OTOH I can think of various reasons why lattice might be preferred

  • lattice renders plots faster
  • lattice has (limited support for) 3D graphics
  • it is easier to customise every aspect of a lattice plot: no ggproto objects, just functions
  • some parameters have no equivalent in ggplot2
  • themes encompass all visual attributes, which I find more natural (e.g. a black and white theme doesn't leave colours in the data layers)

Similarly, base graphics still have distinct advantages over lattice and ggplot2 (and conversely, obviously). An all-around winner could potentially appear and make all previous graphics systems redundant (personal preferences aside), but it hasn't happened so far (it would be a lot of work – look at the gestation period of something like ggvis that merely interfaces with an existing engine).


#17

Seems to me that posting here rather than on https://stat.ethz.ch/mailman/listinfo/r-help will give you replies that would be slightly biased towards ggplot2... :smirk:

To add on what @baptiste wrote about lattice advantages, I often finds myself frustrated with ggplot2 when it comes to fine control of my plots (especially in comparison to lattice with using custom panel and prepanel functions) and with how ggplot2 handles data panelling and grouping (ie, application of colors/symbol/line type within a plot or application of data transformation or processing by group).

People in my field tend to generate 1000s of plots during the development of their models. Speed of plot creation and capabilities to split the data more efficiently in lattice give it a slight edge over ggplot2 in my opinion.

That being said, ggplot2 is easier to learn and to apply in 90% of the cases...


#18

Yeah, as always, @Anantadinath, it's super case dependent— and, this is definitely not a representative sample of R users (the tidyverse category of an RStudio forum could hardly claim to be anything short of heavily biased in the ggplot2 direction).


#19

I'd echo what @jennybryan said; I've lived with all three systems at this point and do almost everything in ggplot2 now. Plus, it is really easy to make most ggplots into interactive plots and I don't think that you can do that with lattice.

I do confess that do still use splom... I find GGally to be as frustrating as base-R level graphics :flushed:


#20

Thanks for this entirely new perspective on the question. I will surely look into the speed part of it more. I usally plot data of around a million rows and thus it takes a minute or 2 to create a plot in ggplot2. If there is some speed attached to it. I would surely look into it.