May 5, 2018
Better viz Anna Cates, a blog reader and soil ecologist working at the University of Wisconsin-Madison had a great suggestion for visualizing market-share change over time for different varietals - the stacked bar chart! I thought I’d write a brief post with some code!
#packages library(tidyverse) library(lubridate) #importing the master data set we've been working with bean_master_import = read_csv(file = "https://raw.githubusercontent.com/keatonwilson/beans/master/data/bean_master_joined.csv?token=AefUVJns3Rn5W9UiDzbkOhHnKJFGyqHNks5bq6oTwA%3D%3D") bean_master_import_bar = bean_master_import %>% mutate(month = month(date), class = factor(class)) %>% group_by(year, month, class) %>% summarize(monthly_mean_market_share = mean(class_market_share)) #Making a new column of just the beginning of each month, since we're binning by month beg_month_date = paste(bean_master_import_bar$year, bean_master_import_bar$month, rep(1, length(bean_master_import_bar$year)), sep = "-") bean_master_import_bar$beg_month_date = ymd(beg_month_date) #Filtering to get rid of some of the noise bean_master_import_bar %>% filter(monthly_mean_market_share < 0.