Stat Bandit

Musings on statistics, computation and data research

ggplot2 joy

I’ve been working on a long-term (25+yr) longitudinal study of rheumatoid arthritis with my boss. He just walked in and asked if I could create a plot showing the trajectory of pain scores over time for each subject, separated by educational level (4 groups). Having now worked with ggplot2 for a while, and learning more at the last two DC useR meetups, I realized that I could formulate this in ggplot very easily and in short order. Hooray!!! Basically, all I needed to do was:

ggplot(data, aes(time, pain, groups=patient.id, color=education.level))+geom_line()

I actually spent more time figuring out how to change the legend title :) (fyi, it is + labs(colour='Education'), with the British spelling being necessary).

I’m actually pretty thrilled that I could use ggplot2 on short order to make this plot.

On another note, my friend Brian Danielak gave a brilliant presentation at last night’s DC R Users meetup on some ggplot2-based development he’s doing for graphical ANOVA. A link to his talk should be on the meetup.com site in short order, so please do check it out.

About these ads

2 responses to “ggplot2 joy

  1. erik s February 26, 2011 at 11:06 AM

    Thanks for the tip. I was wondering how to change the legend the other day and couldn’t figure it out.

    Is there a site or some documentation that covers all these different options? I have the ggplot2 book and have gone through Hadley’s site, but I don’t see all these different options covered?

    • Abhijit February 26, 2011 at 6:03 PM

      Actually that’s a hard one. There is no single source, but it’s often hidden in the example code on Hadley’s ggplot2 site. It’s not systematically covered, and Hadley’s site hasn’t been significantly updated for a while. I often find success using google, which usually brings up entries on the ggplot2 help list, stack overflow or someone’s blog.

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

Follow

Get every new post delivered to your Inbox.

Join 327 other followers

%d bloggers like this: