Occupational Wage Comparison Plotted in R

June 17, 2010

(This article was first published on R-Chart, and kindly contributed to R-bloggers)

Ever have conversations with your kids about what they are going to do with their life? Still trying to figure out what you are going to do with yours?
Best to not starve…

The chart above represents the percentage of each occupation that earn a given hourly wage. The range below represents annual salaries from less than $23,920 (11.50 * 20808) to more than $118,560.

The wage range for various occupations displayed above can be constructed using R. I ran into a couple of issues that perhaps some of you can fix (or provide alternatives). The data is from the Bureau of Labor Statistics and was last modified May 14, 2010 at the time this was posted.
Started with the usual setup.
Problem #1: I could not figure out how to read the header using the readHTMLTable method.
tb = readHTMLTable(url, header=FALSE)[2]$distribution_table
So ended up adding these manually.
colnames(tb)=c(‘Major occupational group’,
‘Under $11.50′,’$11.50 to $14.49′,’$14.50 to $18.24′,’$18.25 to $22.74′,’$22.75 to $28.74′,’$28.75 to $35.99′,’$36.00 to $45.24′,’$45.25 to $56.99′,’Over $57.00’)
Assigned the row names based upon the first column labels (then deleted the first column)

There were percentage signs interspersed in the data, so stripped these out.

Problem #2: How can you fit a legend on a plot like this? Each bar represents 100% (and so all bars are the same size).
par(las=2, mar=c(20, 4, 4, 2) + 0.1, cex=0.85)
barplot(t(tb), main=”Occupational Wage Range”, col=rev(rainbow(9)), names.arg=names(tb))
I eventually decided to display the legend separately and copy it out
barplot(t(tb), main=”Occupational Wage Range”, col=’white’, border=NA)
legend(1, 100, colnames(tb), cex=0.8, fill=rev(rainbow(9)));

I have the feeling that the answer to this questions might be best addressed by something more fundamental, like selecting a different way of representing the data.

To leave a comment for the author, please follow the link and comment on their blog: R-Chart.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.

Search R-bloggers


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)