knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

plot(pressure)

Note that the echo = TRUE parameter was added to the code chunk to prevent printing of the R code that generated the plot. install.packages(‘dplyr’) install.packages(“kableExtra”) install.packages(“readr”) install.packages(“tidyverse”) install.packages(“tidyr”) install.packages(“ggplot2”) install.packages(“ggmap”) install.packages(“data.table”) install.packages(“vtable”) install.packages(“magrittr”) install.packages(“shiny”) install.packages(“ggiraph”) library(dplyr) library(kableExtra) library(vtable) vtable(zip_info, lush = TRUE) library(magrittr) library(readr) library(tidyverse) library(tidyr) library(ggplot2) library(ggmap) library(data.table) library(shiny) library(ggiraph) coffee_survey <- readr::read_csv(‘https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-05-14/coffee_survey.csv’) install.packages(“tidytuesdayR”) tuesdata <- tidytuesdayR::tt_load(2024, week = 20)

coffee_survey <- tuesdata$coffee_survey

make a graph that highlights and points out the most populare addition wanted/used per coffee type and when hovering over it will highlight the additions

library(plotly) library(dplyr)

dataset creation

set.seed(123) coffee_survey <- data.frame( submission_id = 1:100, age = sample(18:70, 100, replace = TRUE), cups = sample(1:5, 100, replace = TRUE), where_drink = sample(c(“Home”, “Work”, “Cafe”), 100, replace = TRUE), brew = sample(c(“Drip”, “Espresso”, “French Press”, “Other”), 100, replace = TRUE), brew_other = NA, purchase = sample(c(“Store”, “Online”), 100, replace = TRUE), purchase_other = NA, favorite = sample(c(“Americano”, “Blended drink (e.g. Frappuccino)”, “Cappuccino”, “Cold Brew”, “Cortado”, “Espresso”, “Iced coffee”, “Latte”, “Mocha”, “Other”, “Pourover”, “Regular drip coffee”), 100, replace = TRUE), favorite_specify = NA, additions = sample(c( “No - just black”, “Sugar or sweetener, No - just black”, “No - just black, Cinnamon”, “Half & half”, NA, “Milk, dairy alternative, or coffee creamer, Sugar or sweetener, Flavor syrup”, “No - just black, Milk, dairy alternative, or coffee creamer”, “Milk, dairy alternative, or coffee creamer, Sugar or sweetener” ), 100, replace = TRUE), additions_other = NA, dairy = sample(c(“Milk”, “Cream”, “None”), 100, replace = TRUE), sweetener = sample(c(“Sugar”, “Sweetener”, “None”), 100, replace = TRUE), style = sample(c(“Hot”, “Iced”), 100, replace = TRUE), strength = sample(1:5, 100, replace = TRUE), roast_level = sample(c(“Light”, “Medium”, “Dark”), 100, replace = TRUE), caffine = sample(c(“Decaf”, “Regular”), 100, replace = TRUE), expertise = sample(c(“Novice”, “Intermediate”, “Expert”), 100, replace = TRUE), coffee_a_bitterness = sample(1:5, 100, replace = TRUE), coffee_a_acidity = sample(1:5, 100, replace = TRUE), coffee_a_personal_preference = sample(1:5, 100, replace = TRUE), coffee_a_notes = NA )

plotly graph

p <- plot_ly(most_popular_addition, x = ~favorite, y = ~count, type = “bar”, hoverinfo = “text”, text = ~paste(“Addition:”, additions, “
Count:”, count)) %>% layout(title = “Most Popular Addition for Each Coffee Type”, xaxis = list(title = “Coffee Type”), yaxis = list(title = “Count”))

Display the plot

p

#show that the trend in coffee intake is a lot higher with those who are in a “working class” and in the age group that is starting to have more kids. Therefore they will have a higher caffine intake.

Load libraries

library(ggplot2)

Define the order of age groups

age_order <- c(“<18 years old”, “18-24 years old”, “25-34 years old”, “35-44 years old”, “45-54 years old”, “55-64 years old”, “>65 years old”)

Plot the data

ggplot(coffee_survey, aes(x = factor(age, levels = age_order), fill = favorite)) + geom_bar(position = “dodge”) + labs(title = “Favorite Coffee Type by Age Group”, x = “Age Group”, y = “Count”, fill = “Favorite Coffee Type”) + theme_minimal() + theme(axis.text.x = element_text(angle = 45, hjust = 1))