# Here is some code to get you started
states = map_data("state")
# Read in the data from http://www.google.org/flutrends/us/data.txt
# ** you will need to figure this part out **
# ** it is NOT trivial **
fluTrends = read.csv(file="http://www.google.org/flutrends/about/data/flu/us/data.txt",
skip = 11,
check.names=FALSE)
# Keep only the last row for the states
flu_w = fluTrends[nrow(fluTrends), c(1,3:53)]
# Reshape to long format
flu_l <- flu_w %>%
gather(region, index, -Date)
# Merge flutrends data with map_data
flu_l$region = tolower(flu_l$region)
states_merged = merge(states, flu_l, sort=FALSE, by='region')
# Find the date
states_merged$Date = as.Date(states_merged$Date)
mx_date = max(states_merged$Date)
# Construct plot
ggplot(states_merged, aes(x=long, y=lat, group=group, fill=index)) +
geom_polygon() +
labs(title=paste('Google Flu Trends on', mx_date), x='', y='') +
theme_minimal() +
theme(legend.title = element_blank()) +
coord_map("cylindrical")