# Response to Flowingdata Challenge: Graphing obesity trends

April 29, 2010
By

[This article was first published on The Pretty Graph Blog » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Nathan at Flowingata put up another interesting challenge today to improve the following graphic showing obesity trends in America.

Here’s my attempt:

I transposed the data so that the cohorts are on the X axis and each separate line represents an age group. So each line shows the percentage of obese people in a particular age group. This way the graph tells you the probability of you being obese at a given age in a particular decade.

For each age group, the line roughly trends upwards. For example, the lavender (violet? 3rd from bottom) line shows that if you were in your twenties during the World War II chances of you being obese were just below 10%, but if you were in your twenties during the mid 60s-70s (rocking out to The Doors?) you were more than twice as likely to be obese.

So, from a cursory look, it does seem that Americans have been getting obese faster.

For those interested, here’s my modified data file and the R code:

colnames(o)<-c(“Age group”,”2-9 Y”,”10-19 Y”,”20-29 Y”,”30-39 Y”,”40-49 Y”,”50-59 Y”,”60-69 Y”,”70-79 Y”)

library(RColorBrewer)
pal<-brewer.pal(length(colnames(o)),”Set1″)

plot(o[,2],pch=19,xaxt=”n”,col=pal[2],type=”o”,ylim=c(0,max(o[,-1],na.rm=T)),xlab=”Cohort by Decade”,ylab=”Percentage of Obese People”,main=”Obesity trends by Age Group”)

for(i in 3:length(colnames(o))) {
points(o[,i],pch=19,xaxt=”n”,col=pal[i])
lines(o[,i],pch=19,xaxt=”n”,col=pal[i])
}

axis(1,at=1:length(o[,1]),labels=o[,1],cex.axis=0.75)

legend(“topright”,legend=colnames(o)[-1],col=pal[-1],lty=1,pch=19,bty=”n”)

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}