R – Lattice, Trellis another awesome framework for data visualization.

This whole post originates from this stackoverflow question. The original poster(OP) was having a hard time putting multiple `plots` into the same canvas. It looks like he was using the base plot function and I assumed the par(mfrow) will be enough in that case. However, it turned out this is a way more interesting question than I first realized and here are all the `aha`s.

He was using a library called DoseFinding , which is

a package provides functions for the design and analysis of does-finding experiments(for example, pharmaceutical Phase II clinical trials).

In there you can use the base plot function to plot the return object from the function `fitMod` (the does response model). You can see the return class of fitMod is called “DRMod” (drug response model) and the plot class is called “Trellis”.

Actually, Trellis is a whole visualization framework developed by the Bell Lab and AT&T Research.  Here is another post to understand post to give you a basic understanding of lattice and trellis.

I have working working with the base plot functions like boxplot, hist, plot.. and also ggplot2 from Hadley Wickham for a while, and I am surprised to find out how easy it is to use lattice package to draw plots taking multiple variables into consideration.


bwplot( mpg ~ cyl.f | gear.f * am)


ggplot(data=mtcars, aes(x=as.factor(cyl), y=mpg)) + geom_boxplot() + facet_wrap(~gear + am)

There are also so many different plot methods in lattice, which you can spend more time exploring.

This Post was posted in R. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s