Specialty coffee has become popular these last couple of years. Sociey has change their preference for coffee chains to specialized coffee stores. In fact, more often than before we found small coffee shops close to our neighborhoods offering good quality coffee. I do not consider myself the judge of every coffee bean, but a truly enthusiast. I wonder if the quality of the coffee is related with the origin, production, and process.
In this project I will try to answer the question above and more questions The Coffee Dataset is interesting and contains 23 variables, including 8 qualitative variables, and at least 4 quantitative variables that we will use in the visualizations. Some of the variables describes coffee scores and ratings.
#I loaded this libraries that I alreade have loaded in R studiolibrary(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.6.2
Warning: package 'tidyr' was built under R version 4.6.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
library(ggplot2)library(highcharter)
Warning: package 'highcharter' was built under R version 4.6.2
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Highcharts (www.highcharts.com) is a Highsoft software product which is
not free for commercial and Governmental use
library(countrycode)
Warning: package 'countrycode' was built under R version 4.6.2
#I loaded the dataset from my carpet at the DISC C in the laptopcoffee_ratings <-read_csv("C:/Users/MFERN123/DATA_110/coffee_ratings.csv")
Rows: 989 Columns: 23
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (7): Location.Country, Location.Region, Data.Owner, Data.Type.Species, ...
dbl (16): Location.Altitude.Min, Location.Altitude.Max, Location.Altitude.Av...
ℹ 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.
#Exploration of the data the dataset contains 989 observations and 23 variablesdim(coffee_ratings)
[1] 989 23
#Here we can observe a glanze of the dataset head(coffee_ratings)
# A tibble: 6 × 23
Location.Country Location.Region Location.Altitude.Min Location.Altitude.Max
<chr> <chr> <dbl> <dbl>
1 United States kona 0 0
2 Brazil sul de minas - c… 12 12
3 Brazil sul de minas - c… 12 12
4 Ethiopia sidamo 0 0
5 Ethiopia sidamo 0 0
6 United States kona 0 0
# ℹ 19 more variables: Location.Altitude.Average <dbl>, Year <dbl>,
# Data.Owner <chr>, Data.Type.Species <chr>, Data.Type.Variety <chr>,
# `Data.Type.Processing method` <chr>,
# `Data.Production.Number of bags` <dbl>, `Data.Production.Bag weight` <dbl>,
# Data.Scores.Aroma <dbl>, Data.Scores.Flavor <dbl>,
# Data.Scores.Aftertaste <dbl>, Data.Scores.Acidity <dbl>,
# Data.Scores.Body <dbl>, Data.Scores.Balance <dbl>, …
#I use the function structure to see what kind of variables the dataset contains str(coffee_ratings)
#I wanted to make sure if the countries of the dataset where all of them different or if some of them were repeated. I found a misspelling in the name of Ivory Coast, however, the information of this country it has not enough weight in the future visualization, so I decided to do not rename the country. unique(coffee_ratings$Location.Country)
#Here I was checking how many countries I have to try to create a visualization and I realized that there were many of them length(unique(coffee_ratings$Location.Country))
[1] 32
#So I decided to check which ones of them has more observations, but the problem was that countries with good rating score were not in the top of observations registered. That is why I decided to look for other visualizations where I can include more countries sort(table(coffee_ratings$Location.Country),decreasing =TRUE)
Mexico Guatemala
201 168
Colombia United States
128 65
Brazil Honduras
61 48
Costa Rica Tanzania, United Republic Of
43 36
Uganda Ethiopia
36 28
Kenya Thailand
21 20
Indonesia Nicaragua
18 18
China India
16 14
Malawi Peru
11 9
Myanmar Vietnam
8 8
El Salvador Haiti
6 6
Philippines Panama
5 4
Ecuador Burundi
3 2
Cote d?Ivoire Laos
1 1
Papua New Guinea Rwanda
1 1
Taiwan Zambia
1 1
#Getting the average score of the ratings to try to create a visualizations based on the score.coffee_map <- coffee_ratings|>group_by(Location.Country)|>summarise(Average_Score =mean(Data.Scores.Total, na.rm =TRUE))
head(coffee_map)
# A tibble: 6 × 2
Location.Country Average_Score
<chr> <dbl>
1 Brazil 83.0
2 Burundi 81.8
3 China 82.9
4 Colombia 83.2
5 Costa Rica 82.6
6 Cote d?Ivoire 79.3
#I found out that similar to tableau we can create global maps in r, so with the help of chat gpt I create this he made download the library "countrycode" and basically this GeoJSON on Highcharts create a link between the name of the country in my data set with the geographic map trought a the 3 letters with every country is represented in the world matching them with "iso#c"coffee_map <- coffee_map |>mutate(iso3 =countrycode(Location.Country,origin ="country.name",destination ="iso3c"))
# A tibble: 116 × 4
Location.Country Data.Type.Variety average_score average_bags
<chr> <chr> <dbl> <dbl>
1 Brazil Arusha 82.3 67.5
2 Brazil Bourbon 83.9 192.
3 Brazil Catuai 83.0 157.
4 Brazil Mundo Novo 82.3 112.
5 Brazil Yellow Bourbon 84 246.
6 Brazil nan 81.9 160.
7 Burundi Bourbon 83.3 220
8 Burundi nan 80.3 300
9 China Catimor 83.8 3
10 China Other 82.5 1
# ℹ 106 more rows
# I was trying to find a relation between the scores ratings of the coffee beans and the amount produced, however the chart prove me wrong. There is no relationship between score and bags produced ggplot(clean_coffee)+aes(x = average_bags,y = average_score,color = Data.Type.Variety) +geom_point(size =2, alpha =0.6) +geom_smooth(method ="lm",se =FALSE) +scale_color_brewer(palette ="Set2") +labs(title ="Relationship Between Coffee Quality and Production",subtitle ="Comparing total quality scores with the number of bags produced",x ="Total Coffee Quality Score",y ="Number of Bags Produced",color ="Coffee Variety",caption ="Source: Original coffee ratings dataset") +theme_minimal()
`geom_smooth()` using formula = 'y ~ x'
Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning: Removed 73 rows containing missing values or values outside the scale range
(`geom_point()`).
#I wanted to know wich ones were the top 5 best ranked coffee beans top_5_coffee <- clean_coffee %>%arrange(desc(average_score)) %>%slice_head(n =5)top_5_coffee
# A tibble: 5 × 4
Location.Country Data.Type.Variety average_score average_bags
<chr> <chr> <dbl> <dbl>
1 Peru Other 88.8 100
2 Thailand Caturra 86.2 53
3 Ethiopia Other 86.2 211.
4 Ethiopia Ethiopian Yirgacheffe 86.0 250
5 Panama Gesha 85.8 37
#Here I wanted to know wich were the top 5 coffee producerstop_5_coffee_producers <- clean_coffee %>%arrange(desc(average_bags)) %>%slice_head(n =5)top_5_coffee_producers
Later I was trying to find a relation between the scores and production but I did not have enough time to finish my research.
But I can conclude that even if Ethiopia is not between the top 5 coffee producers in the world, the quality of their coffee beans is consistent with the bags produced. In addition, Peru appears as good quality beans producer (Top 5), but this information is not supported since the data set does not contain the name of the coffee variety.
India also appears in the top 5 producers countries, but checking the data set the rating scores are low. Which means that they produce big quantities of coffee, but not of the best quality.
Another interesting observation is Panama, which Geisha coffee beans have won several competitions, however there are not many observations of Panama. Also, that can be explained by the size of the country.