library(googlesheets) library(dplyr) library(highcharter) library(htmlwidgets) # THEME #### thm <- hc_theme_merge( hc_theme_google(), hc_theme( colors = c('#92a8d1', '#b1cbbb', '#eea29a', '#c94c4c','#034f84','#b2b2b2'), chart = list(backgroundColor = "transparent" #fontFamily = 'Source Code Pro' ), legend = list(itemStyle = list( #fontFamily = 'Source Code Pro', color = 'grey'), itemHoverStyle = list(color = 'gray'))) ) # IMPORT and CLEAN DATA #### setwd("~/Dropbox/Apps/asocialfolder/davidtingle/files") gs_ls() df <- gs_title("whiskey_ratings") %>% gs_read() dfn <- df %>% unique() %>% filter(category %in% c("Blended Scotch Whisky", "Bourbon/Tennessee", "Irish","Japanese", "Single Malt Scotch", "Rye Whiskey", "Canadian")) %>% mutate(category = replace(category, category == 'Blended Scotch Whisky', 'Blended'), category = replace(category, category == 'Bourbon/Tennessee', 'Bourbon'), category = replace(category, category == 'Rye Whiskey', 'Rye'), category = replace(category, category == 'Single Malt Scotch', 'Single Malt')) pc <- gs_title("price_comparison") %>% gs_read() pcn <- pc %>% gather(bar, bar_price, 7:11) %>% mutate(category = replace(category, category == 'Blended Scotch Whisky', 'Blended'), category = replace(category, category == 'Bourbon/Tennessee', 'Bourbon'), category = replace(category, category == 'Rye Whiskey', 'Rye'), category = replace(category, category == 'Single Malt Scotch', 'Single Malt')) # VISUZALIZE #### chart <- hchart(dfn, "scatter", x = rating, y = lcbo, text = name, group = category, z = category) %>% hc_chart(zoomType = "xy") %>% hc_xAxis(title = list(text = "Whiskey Advocate Rating")) %>% hc_yAxis(title = list(text = "LCBO Bottle Price")) %>% hc_tooltip(useHTML = TRUE, headerFormat = "", pointFormat = paste("", "", "", "", ""), footerFormat = "
{point.label}
Name:{point.text}
Type:{point.z}
Rating:{point.x}
Price:${point.y}
") %>% hc_add_theme(thm) saveWidget(chart, file="lcbo_pri.html") chart2 <- hchart(pcn, "scatter", x = lcbo, y = bar_price, text = name, group = bar, z = category, w = bar) %>% hc_chart(zoomType = "xy") %>% hc_yAxis(title = list(text = "Price per Ounce")) %>% hc_xAxis(title = list(text = "LCBO Bottle Price")) %>% hc_tooltip(useHTML = TRUE, headerFormat = "", pointFormat = paste("", "", "", "", "", ""), footerFormat = "
{point.label}
Name:{point.text}
Type:{point.z}
Markup:{point.w}
LCBO Price:${point.x}
Bar Price:${point.y}
") %>% hc_add_theme(thm) saveWidget(chart2, file="bar_pri.html") highchart() %>% hc_add_series_scatter(df$rating, df$lcbo, text = df$name, color = df$category, dataLabels = F) %>% hc_chart(zoomType = "xy") %>% hc_legend(enabled = T) %>% hc_tooltip(useHTML = TRUE, headerFormat = "", pointFormat = paste("", "", "", "", ""), footerFormat = "
{point.label}
Name:{point.text}
Type:{point.valuecolor}
Rating:{point.x}
Price:{point.y}
") %>% hc_add_theme(hc_theme_google())