Comparing two populations using different graph types

October 5th, 2007

I think the title says it all. If you have two populations such as “Treatment” and “Control”, what type of graphs can you use to compare the two? Have a look at the examples, then pick the corresponding R code.

All of the charts come from either excellent the lattice package, or the superb ggplot2 package. The code should also work for multiple populations as well.

lattice

Box plot

Lattice box plot

Violin plot

Lattice violin plot

Density plot

Lattice density plot

ggplot2

Box and whisker plot

ggplot2 box plot

Box and whisker plot with points

ggplot2 box and whisker plot with points

Density plot

ggplot2 density plot

Histogram plot

ggplot2 histogram plot

5 responses

  1. Tiago Antao comments:

    Just a couple of suggestions on “competitive” platforms:

    1. With Python, matplotlib is amazing, and very easy to use. The 3D graphics are very cool as they are interactive (one can rotate/zoom them, no code involved). It seems to produce publication quality graphics by default.
    2. With Java, there is JFreeChart. Dreadful to use (hey, its a Java API, it could not be easy), but with lots of options and flexibility (hey, its Java… ;) ). No 3D, though.

  2. Neil comments:

    Nice summary. I wish I’d had some formal training in R; it’s something I use occasionally and it feels like I’m relearning the basics every time I go back to it. I often feel like there’s almost nothing it can’t do, from basic stats and plotting to complex custom scripts for bioinformatics, but good how-tos and tutorials are few and far between.

  3. Animesh comments:

    I am still stuck with matlab plot :(

  4. Mr. Gunn comments:

    Matlab? EXCEL FTW LOL!

    Here’s some R tutorials.

  5. Animesh Sharma comments:

    Heheheh, I am getting in love with demo(smooth) now!

Leave a comment