Data Dive Week 2: Yuritzi Avila-Robledo

Directions:

Your RMarkdown notebook for this data dive should contain the following:

1) Summary of data for at least 2 columns of data

Numeric

For my data dive assignment I will be looking at the chocolate.csv. I started off by importing my data and loading in the tidyverse package.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
chocolate <- read.csv("~/Desktop/chocolate.csv")
library(readr)
summary(chocolate)
##       ref       company_manufacturer company_location    review_date  
##  Min.   :   5   Length:2530          Length:2530        Min.   :2006  
##  1st Qu.: 802   Class :character     Class :character   1st Qu.:2012  
##  Median :1454   Mode  :character     Mode  :character   Median :2015  
##  Mean   :1430                                           Mean   :2014  
##  3rd Qu.:2079                                           3rd Qu.:2018  
##  Max.   :2712                                           Max.   :2021  
##  country_of_bean_origin specific_bean_origin_or_bar_name cocoa_percent   
##  Length:2530            Length:2530                      Min.   :0.4200  
##  Class :character       Class :character                 1st Qu.:0.7000  
##  Mode  :character       Mode  :character                 Median :0.7000  
##                                                          Mean   :0.7164  
##                                                          3rd Qu.:0.7400  
##                                                          Max.   :1.0000  
##  ingredients        most_memorable_characteristics     rating     
##  Length:2530        Length:2530                    Min.   :1.000  
##  Class :character   Class :character               1st Qu.:3.000  
##  Mode  :character   Mode  :character               Median :3.250  
##                                                    Mean   :3.196  
##                                                    3rd Qu.:3.500  
##                                                    Max.   :4.000

From the summary listed above we are able to see that the average percent of cocoa in the cocoa beans used to produce chocolate was 70% , while the minimum was 42%. The earliest rating was in the year 2006 while the latest year was 2021, that gives us a range of 15 years of reviews. The highest rating was a 4, the lowest a 1, and the average rating was a 3.196. From this summary, we received only insight into the numerical data, now I will move onto taking a look at what the categorical data provides.

Categorical

For the categorical data I wanted to take a look at how many countries the cocoa beans originated from.

library(tidyverse)

chocolate |>
  distinct(country_of_bean_origin) |>
  count()
##    n
## 1 62

I thought it would be interesting to see the different ingredients used in the chocolates so I decided to use the distinct function:

chocolate |>
  distinct(ingredients)
##       ingredients
## 1        3- B,S,C
## 2      4- B,S,C,L
## 3          2- B,S
## 4      4- B,S,C,V
## 5    5- B,S,C,V,L
## 6  6-B,S,C,V,L,Sa
## 7    5-B,S,C,V,Sa
## 8                
## 9      4- B,S,V,L
## 10        2- B,S*
## 11           1- B
## 12      3- B,S*,C
## 13       3- B,S,L
## 14       3- B,S,V
## 15    4- B,S*,C,L
## 16   4- B,S*,C,Sa
## 17     3- B,S*,Sa
## 18    4- B,S,C,Sa
## 19    4- B,S*,V,L
## 20         2- B,C
## 21    4- B,S*,C,V
## 22  5- B,S,C,L,Sa

2) A set of at least 3 novel questions to investigate

Question 1: Does the percent of cocoa affect the rating of the chocolate?

Question 2: Does the country the cocoa bean originates from affect the percentage of cocoa?

Question 3: What affect does the manufacturer have on the rating of the chocolate?

3) Address at least one of the above questions using an aggregation function/Visual summaries (i.e., visualizations) of 2 or more columns of your data

Question 1: Does the percent of cocoa affect the rating of the chocolate?

I thought it would be interesting to see how having the max percentage of cocoa affects the rating of the chocolate which turned out to have a rating of 2 and 3.25 which is lower than expected. I’d assume the richer the chocolate is in cocoa the higher the rating.

chocolate|>
  group_by(rating)|>
  filter(cocoa_percent=="0.99")
## # A tibble: 2 × 10
## # Groups:   rating [2]
##     ref company_manufacturer company_location review_date country_of_bean_origin
##   <int> <chr>                <chr>                  <int> <chr>                 
## 1    81 Michel Cluizel       France                  2006 Blend                 
## 2   915 TCHO                 U.S.A.                  2012 Blend                 
## # ℹ 5 more variables: specific_bean_origin_or_bar_name <chr>,
## #   cocoa_percent <dbl>, ingredients <chr>,
## #   most_memorable_characteristics <chr>, rating <dbl>

After the last results I wanted to created a visualization and try to find a linear trend on all the percentages of cocoa versus their ratings.

ggplot(chocolate,aes(x=cocoa_percent, y=rating))+geom_point(color="red")+labs(x="Cocoa Percentage",y="Rating", title="Cocoa Percentage vs Rating")+geom_smooth(method="lm",se=FALSE)
## `geom_smooth()` using formula = 'y ~ x'

From this plot of cocoa percentage versus rating we are able to see that there is a decreasing linear trend where as cocoa percentage increases the rating decreases. This was a surprise as I’d assume the richer in cocoa the chocolate is the better the chocolate.

Question 2: Does the country the cocoa bean originates from affect the percentage of cocoa?

I thought it would be interesting to find the average cocoa percentage per country of bean origin in order to see which country’s land is richer in cocoa. If there were more data available it would be really interesting to see if the countries weather affects the percentage of cocoa which also affects the rating.

library(dplyr)
average_cocoa_per_country <- chocolate |>
  group_by(country_of_bean_origin) |>
  summarize(avg_cocoa_percentage = mean(cocoa_percent,na.rm = TRUE))
ggplot(average_cocoa_per_country,aes(x=country_of_bean_origin, y=avg_cocoa_percentage))+geom_bar(stat="identity",fill="red")+labs(x="Country",y="Avg Cocoa Percentage", title="Average Cocoa Percentage per Country")+ theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust=1))

Question 3: What affect does the manufacturer have on the rating of the chocolate?

Following along the same lines as the second question, I thought it would be interesting to see how the manufacturer’s company location affects the average rating of the chocolate. My interest for this may not be fulled answered by the data available but I was interested in seeing if the further away the company’s manufacturers location is from where the cocoa bean originated, maybe the rating decreases for their chocolate because of the distance the cocoa beans have to travel. This is what I gathered with what I had available:

rating_based_on_manufacturer <- chocolate |>
  group_by(company_location)|>
  summarize(avg_rating = mean(rating,na.rm = TRUE))
ggplot(rating_based_on_manufacturer,aes(x=company_location,y=avg_rating))+geom_bar(stat="identity",fill="red")+labs(x="Manufacturer",y="Avg Rating", title="Manufacturers Average Rating")+ theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust=1))

It looks like I have to get my hands on some chocolate manufactured from Canada!