u <- read.table("la.data.3.AllStatesS", header=T, fill=T)
# Convert the months into fractional years
u$time <- u$year + (as.numeric(u$period) - 1) / 12
# Get just the measurement values (those that end in "03")
m <- u[grep("03$", u$series_id),]
# And ignore the ones that are in Puerto-rico, state code 43
m <- subset(m, series_id != "LASST43000003")
# make the year a factor
m$year <- as.factor(m$year)
# Aggregate all samples into a single year average
# leaving per-state data intact
v <- aggregate(m, list(year=m$year, series_id=m$series_id), mean)
# Aggregate all samples into a per-month average
m2 <- aggregate(m, list(year=m$year, period=m$period), mean, na.rm=T)
m2 <- m2[order(m2$time),]
#m2 <- aggregate(m, list(year=m$year), mean, na.rm=T)
# And generate the box plot for every state
par(family="Times")
par(bty="n")
plot(
value ~ year,
data = v,
ylim = c(0,16),
main = "US Seasonally Adjusted Unemployment",
ylab = "Unemployment rate",
xlab = "Year",
las=1
)
grid()
# Add the moving average line
par(new=T)
par(bty="n")
plot(
value ~ time,
data = m2,
col = "red",
type = "l",
ylim = c(0,16),
xlim = c(1976,2011),
main = "",
xlab = "",
ylab = "",
axes = F
);
dev.copy(svg, "US Seasonal Unemployment.svg", width=8, height=6)
dev.off()