#TidyTuesday Honey Production

title: "R Notebook for Tidy Tuesday" output: word_document: default html_document:

df_print: paged

This is an R Markdown Notebook for the #TidyTuesday challenge: a weekly social data project (in R), which builds off #makeovermonday style projects but aimed at the R ecosystem. An emphasis will be placed on understanding how to summarize and arrange data to make meaningful charts with ggplot2, tidyr, dplyr, and other tools in the tidyverse ecosystem.

This code is for Week 7, and my effort to recreate [this image] (http://www.beeculture.com/u-s-honey-industry-report-2016/) downloaded from this source

library(tidyverse, quietly = TRUE, warn.conflicts = FALSE) #because...duh
library(readxl)
library(viridis) #awesome color-blind friendly palette
library(janitor) #clean data

#import data

honey_raw <- read_csv("honeyproduction.csv") %>% 
  clean_names() %>% 
  as.tibble()

#get a feel for data
class(honey_raw)
dim(honey_raw) #rows,col
names(honey_raw)
glimpse(honey_raw) #dplyr version of str()


View(honey_raw)
honey_raw %>% group_by(year) %>% 
  summarize_each(funs(mean))

honey_raw %>% group_by(year) %>% 
  summarize_each(funs(mean)) %>% 
  ggplot() +
  geom_point(aes(x = year, y = totalprod, size = numcol, fill = yieldpercol), shape = 21, color = "darkgray") +
  geom_smooth(aes(x = year, y = totalprod), span = 2, se = FALSE, color = "gray", linetype = "dotted") +
  scale_fill_viridis(direction = -1, option = "A", name = "Yield per Colony\n(pounds)") +
  scale_y_continuous(limits = c(3000000, 5500000), breaks = c(3000000, 3500000, 4000000, 4500000, 5000000, 5500000), labels = c(3.0, 3.5, 4.0, 4.5, 5.0, 5.5)) +
  scale_x_continuous(limits = c(1998, 2012), breaks = c(1998, 2000, 2002, 2004, 2006, 2008, 2010, 2012)) +
  guides(size = guide_legend("Honey Producing\nColonies"), limits = c(55000, 65000)) +
  theme_minimal() +
  labs(caption = "Plot by @hirscheylab | beeculture.com", 
       title = "Total U.S. Honey Production Decreases", 
       x = "Year", 
       y = "US Honey Production (millions of pounds)")

#save

ggsave("honey.png", last_plot(), height = 4, width = 6, units = "in", dpi = 600)
#default is last plot, but can name objects here