# Response to Flowingdata Challenge: Graphing obesity trends

**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:

o<-read.csv(“obesity_edit.csv”)

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”)

**leave a comment**for the author, please follow the link and comment on their blog:

**The Pretty Graph Blog » R**.

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.