Other sites

Occupational Wage Comparison Plotted in R

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.

library(XML)

url=’http://www.bls.gov/oes/current/distribution_table.htm’

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)

rownames(tb)=tb[,1]

tb=tb[-1]

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

tb=sub(‘%’,”,as.matrix(tb))

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