Introduction

Starbucks is one of the most popular chains of cafes, famous for their seasonal pumpkin-spice lattes, Chai-tea lattes, pink drinks, and more. Starbucks has gained major popularity over the years and only increased its locations. From coffee to tea to frappuccinos, and many different substitutions and additions, Starbucks’ drink menu is vast, but what about their food items? This openInro Starbucks data set explores Starbucks’ food items and their nutritional values. Containing 77 rows and 7 columns, we learn about the type of items available, their calorie count, and protein, carb, fiber, and fat contents. Most variables in this data set are numeric as they describe how much nutrients are in each food item (in grams). The other type of variable is categorical as it describes the type of food each menu item is considered, whether it is bakery or sandwich or petite, etc. I used to go to Starbucks cafes often, I would try and explore their menu and I have yet to hear that Starbucks offers healthy nutritional foods, so I’ve chosen to explore this topic myself.

Loading necessary libraries and introuducing the data set

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0     ✔ purrr   1.0.1
## ✔ tibble  3.1.8     ✔ dplyr   1.1.0
## ✔ tidyr   1.3.0     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(RColorBrewer)
library(scales)
## 
## Attaching package: 'scales'
## 
## The following object is masked from 'package:purrr':
## 
##     discard
## 
## The following object is masked from 'package:readr':
## 
##     col_factor
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 4.2.3
library(highcharter)
## Warning: package 'highcharter' was built under R version 4.2.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
starbucks <- read_csv("starbucks.csv")
## Rows: 77 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): item, type
## dbl (5): calories, fat, carb, fiber, protein
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Exploring dataset

In order to take a look at the data set, I used the structure function to see the type of variables I would be exploring.

str(starbucks)
## spc_tbl_ [77 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ item    : chr [1:77] "8-Grain Roll" "Apple Bran Muffin" "Apple Fritter" "Banana Nut Loaf" ...
##  $ calories: num [1:77] 350 350 420 490 130 370 460 370 310 420 ...
##  $ fat     : num [1:77] 8 9 20 19 6 14 22 14 18 25 ...
##  $ carb    : num [1:77] 67 64 59 75 17 47 61 55 32 39 ...
##  $ fiber   : num [1:77] 5 7 0 4 0 5 2 0 0 0 ...
##  $ protein : num [1:77] 10 6 5 7 0 6 7 6 5 7 ...
##  $ type    : chr [1:77] "bakery" "bakery" "bakery" "bakery" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   item = col_character(),
##   ..   calories = col_double(),
##   ..   fat = col_double(),
##   ..   carb = col_double(),
##   ..   fiber = col_double(),
##   ..   protein = col_double(),
##   ..   type = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>

My First Plot

For the first plot, I used high charter to create an interactive boxplot to look at the different types of foods Starbucks offers and the range of their calorie count.

plot1 <- hcboxplot(
  x = starbucks$calories,
  var = starbucks$type,
  name = "Length",
  outliers = TRUE
) %>%
  hc_title(text = "Calories Count of each Menu Type") %>%
  hc_xAxis(title = list(text="Type of Item")) %>%
  hc_yAxis(title = list(text="Calorie Count")) 
## Warning: 'hcboxplot' is deprecated.
## Use 'data_to_boxplot' instead.
## See help("Deprecated")
## Warning: `unite_()` was deprecated in tidyr 1.2.0.
## ℹ Please use `unite()` instead.
## ℹ The deprecated feature was likely used in the highcharter package.
##   Please report the issue at <]8;;https://github.com/jbkunst/highcharter/issueshttps://github.com/jbkunst/highcharter/issues]8;;>.
plot1 %>% hc_add_theme(hc_theme_darkunica())

Another way to look at the Menu

This plot is similar to the first one, in that it looks at the calorie count of different menu items, but it also offers the name of each item.

plot2 <- highchart() %>%
  hc_add_series(data = starbucks,
                   type = "lollipop", hcaes(x = item,
                   y = calories, 
                   group = type)) %>%
  hc_title(text = "Calories Count of each Menu Item") %>%
  hc_yAxis(title = list(text="Calorie Count")) 

plot2  %>% hc_add_theme(hc_theme_ffx())

Here is another graph that looks at all the Nutritional Values

In this plot, I wanted to see how much fiber was offered by Starbucks. I wanted to add a tooltip so that you can see the other nutritional values and the name of the items.

plot4 <- ggplot(starbucks, aes(x = fiber, y = calories, color = type, group = 1)) +
  geom_point(aes(text = 
                   paste(paste("item", item, "<br>"),
                         paste("calories", calories, "<br>"),
                         paste("protein", protein, "<br>"),
                         paste("carb", carb, "<br>"),
                         paste("fat", fat, "<br>"),
                         paste("fiber", fiber, "<br>")))) + 
  scale_colour_brewer(type = "seq", palette = "Spectral") +
  labs( title = "Nutritional Values of Starbucks Menu Item",
        x = "Fiber Content (Grams)",
        y = "Claorie Count")
## Warning in geom_point(aes(text = paste(paste("item", item, "<br>"),
## paste("calories", : Ignoring unknown aesthetics: text
plot5 <- ggplotly(plot4, tooltip = "text") 

plot5

Exploring the Fat Content in the Menu

This last plot only explores the fat content and calorie count of the menu items. I also wanted to try and customize it on my own, so I created a small color palette and I changed the font.

colors <- c("#04316c", "#1078ab", "#69bdd2", 
           "#80391e", "#e07b39", "#ebb678","#c4ecec")
plot3 <- highchart() %>%
  hc_add_series(data = starbucks,
                   type = "point", hcaes(x = calories,
                   y = fat, 
                   group = type)) %>%
  hc_colors(colors) %>%
  hc_chart(style = list(fontFamily = "Times",
                        fontWeight = "bold")) %>%
  hc_title(text = "Calories Count and Fat Content of Starbucks Menu Items") %>%
  hc_xAxis(title = list(text="Calorie Count")) %>%
  hc_yAxis(title = list(text="Fat (grams)")) %>%
  hc_legend(align = "right", layout = "vertical")

plot3

Conclusion

Founded by Jerry Baldwin, Gordon Bowker, and Zev Siegl, Starbucks opened its first store in 1971, offering coffee, teas, and spices, for their customers to try and take home. And in the 1980s, they opened up four more stores in Seattle and were considered strong competitors. In 2003, they began to offer food items to accompany their different drinks. Starbucks continues to offer many different food items, but they have changed over the years to fit the customers’ palettes.

The visualizations I wanted to create mainly focused on the calorie count of the different items. It has become very common to consume high-calorie small snacks that can negatively affect our health. One main thing I learned from looking at the different plots is that these items never have more than 500 calories, keeping in mind, that this is from 2011. Which most likely means that they are different items now available at Starbucks. One of the plots does show the fiber content, but it is never above 7 grams. And another plot shows the calories and fat content. It was quite obvious that as the calories increases, the fat content would increase, but I was curious as to why Starbucks had only one zero-calorie item, and all other items had over 100 calories.