It seems I have been visiting some government statistics websites more and more frequently lately. Websites like the Bureau of Justice Statistics or the Bureau of Labor Statistics, though somewhat difficult to navigate, are great resources for exciting data for someone looking for something to do on the weekend. The world is your oyster. Since I have been messing with those datasets recently (Justice statistics post to come early next week) I wanted to find something different. Enter the USDA Economic Research Service with data on Agricultural Productivity in the US.
I decided it would be a nice exercise if I limited myself to only 10 lines or less. This could be interpreted differently so I operated on the idea that the operational part had to be 10 lines, not packages or setting up the environment. It turned out to be a little harder than I thought. My first objective was to find and manipulate the data. I decided at the start that the data had to be harvested and tidied in R, sort of like starting from scratch. So using
rvest I imported the data from the USDA. Originally I planned on comparing output and input prices in the US, but I was eating my breakfast while doing this so I found the livestock outputs… topical. The result is not super exciting, but a fun and challenging first go at this thing.
library(ggplot2) library(rvest) library(tidyr) #begin stuff livestock<-read.csv('https://www.ers.usda.gov/webdocs/DataFiles/Agricultural_Productivity_in_the_US__17966/table01a.csv?v=42352',skip=1,stringsAsFactors = F) livestock<-livestock[-c(1),] livestock.df<-select(livestock,Year,dairy=Dairy.1,meat=Meat_animals.1,poultry=Poultry_and_eggs.1) livestock.df<-livestock.df%>%gather(Product,Quantity,2:4) livestock.df$Quantity<-as.numeric(livestock.df$Quantity) ggplot(livestock.df,aes(x=Year,y=Quantity))+ geom_point(aes(group=Product,color=Product))+ theme_awhstin()+ #you will have to change your theme theme(axis.text.x = element_text(angle=90))+ labs(x='',y='',title='US Livestock Production', subtitle='Output Quantity of Livestock Products from 1948-2013', caption='Source: USDA, Economic Research Service,\nProductivity in the United States data product, updated December 2015.')