This is a newbie question. I want to plot the state level unemployment in the US map. There have been profound discussions here and elsewhere about how to plot county level unemployment and the issues associated with it. The code looks intimidating to me. Is there a simple code out there which takes two columns, a state code and a factor variable indicating numeric intervals and yields a colored US map(based on the factor variable). A supplementary question is that if I need to go a little further and create similar plot but with unemployment rate in major cities of US how do I modify the code. Thank you in advance.
In general, the unemployment rate in the United States is obtained by dividing the number of unemployed persons by the number of persons in the labor force (employed or unemployed) and multiplying that figure by 100.
The steady state rate of unemployment, also called the natural rate of unemployment, is the average unemployment rate around which the economy fluctuates. The labor market is said to be in a steady state, or long-run equilibrium, when the rate of unemployment is constant.
Unemployment Minnesota had the lowest jobless rate in August, 1.9 percent. The next lowest rates were in New Hampshire and Utah, 2.0 percent each. The rate in Louisiana, 3.5 percent, set a new series low (all state series begin in 1976).
Here is a quick piece of code with comments explaining each step. Let me know if you have questions
# load libraries
library(XML);
library(ggplot2);
library(maps);
library(plyr);
# read the data from the bls website with correct column formats
unemp = readHTMLTable('http://www.bls.gov/web/laus/laumstrk.htm',
colClasses = c('character', 'character', 'numeric'))[[2]];
# rename columns and convert region to lowercase
names(unemp) = c('rank', 'region', 'rate');
unemp$region = tolower(unemp$region);
# get us state map data and merge with unemp
us_state_map = map_data('state');
map_data = merge(unemp, us_state_map, by = 'region');
# keep data sorted by polygon order
map_data = arrange(map_data, order);
# plot map using ggplot2
p0 = ggplot(map_data, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = cut_number(rate, 5))) +
geom_path(colour = 'gray', linestyle = 2) +
scale_fill_brewer('Unemployment Rate (Jan 2011)', pal = 'PuRd') +
coord_map();
#You may need to spell out the argument pal as pallete
Ramnath nailed this one. If you're still looking for other solutions, there's a decent example using other packages at the SAS-and-R blog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With