NSCB Sexy Stats Version 2

[This article was first published on Data Analysis and Visualization in 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.

This was a revised version of my previous post about the NSCB article. With the suggestion from Tal Galili, below were the new pie charts and the R codes to produce these plots by directly scrapping the data from the webpage using XML and RColorBrewer pagkage.

Unemployment by Age Group

Unemployment by Gender

Unemployment by Civil Status

Unemployment by Educational Level




##################################################################################

library (XML)
library(RColorBrewer)
 

url<-"http://www.nscb.gov.ph/sexystats/2012/Filipinoversion/SS20121022_joblessness_filver.asp"
unemployment<-readHTMLTable(url, header=T, which=2,stringsAsFactors=F)
agegroup<-unemployment[3:8,c(1,3,5)]
gender<-unemployment[12:13,c(1,3,5)]
civil<-unemployment[17:20,c(1,3,5)]
education<-unemployment[25:31,c(1,3,5)]


#Copy to clipboard
Education    Y2006    Y2009
Elementary     42.5    37.9
High School    47.7    52.2
College    9.7    10


educ<-read.table("clipboard", header=T, sep="\t")

colnames(agegroup)<-c("Age.Group","Y2006","Y2009")
colnames(gender)<-c("Gender","Y2006","Y2009")
colnames(civil)<-c("Civil.Status","Y2006","Y2009")
colnames(education)<-c("Education","Y2006","Y2009")

agegroup$Age.Group[6]<-"65 & Up"
agegroup$Y2006<-as.numeric(agegroup$Y2006)
agegroup$Y2009<-as.numeric(agegroup$Y2009)

gender$Gender[2]<-"Female"
gender$Gender[1]<-"Male"
gender$Y2006<-as.numeric(gender$Y2006)
gender$Y2009<-as.numeric(gender$Y2009)

civil$Y2006<-as.numeric(civil$Y2006)
civil$Y2009<-as.numeric(civil$Y2009)
cs<-c("Single","Married","Widowed", "Divorced")

win.graph(w=14.3,h=7)
par(mfrow=c(1,2), oma=c(1,0,1,1) , mar=c(1,1,0,1))

#Chart 1
pie(agegroup$Y2006,label=agegroup$Age.Group, col=brewer.pal(6,”Set1″), border=”white”)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment\nby Age Group\nYear 2006″, cex=1.5, font=2)

pie(agegroup$Y2009,label=agegroup$Age.Group, col=brewer.pal(6,”Set1″), border=”white”)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment\nby Age Group\nYear 2009″, cex=1.5, font=2)
text(0.5,-1, “Data Source: NSCB\nCreated by: ARSalvacion”, adj=c(0,0), cex=0.7)

#Chart 2
pie(gender$Y2006,label=gender$Gender, col=brewer.pal(2,”Set1″), border=”white”, cex=1.5)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment\nby Gender\nYear 2006″, cex=1.5, font=2)

pie(gender$Y2009,label=gender$Gender, col=brewer.pal(2,”Set1″), border=”white”, cex=1.5)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment\nby Gender\nYear 2009″, cex=1.5, font=2)
text(0.5,-1, “Data Source: NSCB\nCreated by: ARSalvacion”, adj=c(0,0), cex=0.7)

#Chart 3
pie(civil$Y2006,label=cs, col=brewer.pal(4,”Dark2″), border=”white”)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment\nby Civil  Status\nYear 2006″, cex=1.5, font=2)

pie(civil$Y2009,label=cs, col=brewer.pal(4,”Dark2″), border=”white”)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment\nby Civil  Status\nYear 2009″, cex=1.5, font=2)
text(0.5,-1, “Data Source: NSCB\nCreated by: ARSalvacion”, adj=c(0,0), cex=0.7)

#Chart 4
pie(educ$Y2006,label=educ$Education, col=brewer.pal(3,”Dark2″), border=”white”, cex=1.5)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment by\nEducational Level\nYear 2006″, cex=1.5, font=2)

pie(educ$Y2009,label=educ$Education, col=brewer.pal(3,”Dark2″), border=”white”, cex=1.5)
par(new=TRUE) 
pie(c(1), labels=NA, border=’white’, radius=0.4)
text(0,0,labels=”Percent\nUnemployment by\nEducational Level\nYear 2009″, cex=1.5, font=2)
text(0.5,-1, “Data Source: NSCB\nCreated by: ARSalvacion”, adj=c(0,0), cex=0.7)


##################################################################################


To leave a comment for the author, please follow the link and comment on their blog: Data Analysis and Visualization in 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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)