-
Notifications
You must be signed in to change notification settings - Fork 0
/
white_wine.Rmd
678 lines (557 loc) · 25.8 KB
/
white_wine.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
White Wine Quality by Diogo Cosin Ayres de Oliveira
========================================================
This report explores a dataset containing information about 4898 white wines
provided by Cortez et al. (2009). Each observation is described by its chemical
properties and experts quality review.
First, some numbers about the data set.
```{r echo=FALSE, message=FALSE, warning=FALSE, packages}
# Load all of the packages that you end up using in your analysis in this code
# chunk.
# Notice that the parameter "echo" was set to FALSE for this code chunk. This
# prevents the code from displaying in the knitted HTML output. You should set
# echo=FALSE for all code chunks in your file, unless it makes sense for your
# report to show the code that generated a particular plot.
# The other parameters for "message" and "warning" should also be set to FALSE
# for other code chunks once you have verified that each plot comes out as you
# want it to. This will clean up the flow of your report.
library(ggplot2)
library(scales)
library(gridExtra)
library(GGally)
```
```{r echo=FALSE, Load_the_Data}
# Load the Data
setwd("~/documents/udacity/p4/project")
df_ww = read.csv("wineQualityWhites.csv", strip.white = TRUE)
```
```{r echo=FALSE, message=FALSE, warning=FALSE}
dim(df_ww)
```
The data set contains 4898 observation with 13 attributes including one for index
and another for the quality grade.
Below, the summary statics about these 13 attributes.
```{r echo=FALSE, message=FALSE, warning=FALSE}
names(df_ww)
summary(df_ww)
```
# Univariate Plots Section
## Wine Quality
Each wine is rated in a 0 (very bad) - 10 (very excellent) grade by at least 3
wine experts.
```{r echo=FALSE, message=FALSE, warning=FALSE}
summary(df_ww$quality)
```
```{r echo=FALSE, message=FALSE, warning=FALSE, Univariate_Plots}
ggplot(aes(x = quality), data = df_ww) +
geom_bar(color = 'black', fill = '#099DD9') +
xlim(0,10) +
ggtitle('Distribution of Observed Quality Wines') +
xlab('Quality') +
ylab('Count') +
scale_x_continuous(breaks=c(seq(0,10))) +
theme(plot.title = element_text(hjust = 0.5))
```
We see a normal distribution in the quality attribute histogram. Most wines are
reviewed with quality around 6. The maximum quality observed is 9 while minimum
is 3. No wine received a perfect 10 review and just a few has got a 9 review.
Let's try to understand throughout this EDA report what factors produce better
wines, according to experts opinions.
## Acidity Attributes
Now let's visualize the acidity chemical properties of our data set wines.
```{r echo=FALSE, message=FALSE, warning=FALSE}
p1 = ggplot(aes(x = fixed.acidity), data = df_ww) +
geom_histogram(binwidth = 0.2, color = 'black', fill = '#099DD9') +
xlim(2,15) +
ggtitle('Distribution of Fixed Acidity') +
xlab(bquote('Fixed Acidity ['~g/dm^3~ ']')) +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p2 = ggplot(aes(x = volatile.acidity), data = df_ww) +
geom_histogram(binwidth = 0.01, color = 'black', fill = '#099DD9') +
xlim(0,1.2) +
ggtitle('Distribution of Volatile Acidity') +
xlab(bquote('Volatile Acidity ['~g/dm^3~ ']')) +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p3 = ggplot(aes(x = volatile.acidity), data = df_ww) +
geom_histogram(binwidth = 0.01, color = 'black', fill = '#099DD9') +
xlim(0,1.66) +
ggtitle('Distribution of Citric Acid') +
xlab(bquote('Citric Acid ['~g/dm^3~ ']')) +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
grid.arrange(p1,p2,p3,ncol=1)
```
Bellow, it is presented the summary statics of these three attributes.
```{r}
summary(df_ww$fixed.acidity)
summary(df_ww$volatile.acidity)
summary(df_ww$citric.acid)
```
It is noticed a normal distribution in the acidic wines attributes, however we
can see too many residues values to the right causing the maximum values to be
distant from median values. For instance, for fixed acidity the maximum value
observed was 14.2 while the median was 6.8 and the 3rd quartile, 7.3. We see the
same behavior for volatile acidity (median of 0.26, 3rd quartile of 0.32 and
maximum of 1.1) and citric acid (median of 0.32, 3rd quatile of 0.39 and maximum
of 1.66). Can the less frequency bins indicate a higher quality wine once most
wines present median attributes values? Maybe in multivariate analysis we will
find some relationship between these attributes and the wine quality.
## Sulfur and Sulphate Attributes
Following the uni-variate exploration, let's plot the histogram distribution of
the sulfur and sulphate attributes.
```{r echo=FALSE, message=FALSE, warning=FALSE}
p1 = ggplot(aes(x = free.sulfur.dioxide), data = df_ww) +
geom_histogram(binwidth = 5, color = 'black', fill = '#099DD9') +
xlim(0,289) +
ggtitle('Distribution of Free Sulfur Dioxide') +
xlab(bquote('Free Sulfur Dioxide ['~mg/dm^3~ ']')) +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p2 = ggplot(aes(x = total.sulfur.dioxide), data = df_ww) +
geom_histogram(binwidth = 5, color = 'black', fill = '#099DD9') +
xlim(0,440) +
ggtitle('Distribution of Total Sulfur Dioxide') +
xlab(bquote('Volatile Acidity ['~mg/dm^3~ ']')) +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p3 = ggplot(aes(x = 1000*sulphates), data = df_ww) +
geom_histogram(binwidth = 10, color = 'black', fill = '#099DD9') +
xlim(0,1080) +
ggtitle('Distribution of Sulphates') +
xlab(bquote('Sulphates ['~mg/dm^3~ ']')) +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
grid.arrange(p1,p2,p3,ncol=1)
```
Summary stats for the sulfur and sulphates attributes.
```{r}
summary(df_ww$free.sulfur.dioxide)
summary(df_ww$total.sulfur.dioxide)
summary(df_ww$sulphates)
```
Again, as we have seen for the acidic attributes, most wine have same
characteristics regarding its sulphates attributes given that the observations
accumulate around median values. Soon, as the quality distribution is
approximately normal, we may expect that wine with atypical acidic attributes
are better reviewed than median ones and we will test in multivariate analysis.
Regarding the distributions, we notice that free sulfur dioxide presents a long
right tail causing the maximum value to be 289 while the median is 34 and the
3rd quartile, 46. On the other hand, we don't have the same pattern for the left
side as the 1st quartile is 23 and the minimum value, 2.
## pH and Alcohol
Let's plot the related pH and alcohol attributes.
```{r echo=FALSE, message=FALSE, warning=FALSE}
p1 = ggplot(aes(x = pH), data = df_ww) +
geom_histogram(binwidth = 0.01, color = 'black', fill = '#099DD9') +
xlim(2.72,3.82) +
ggtitle('Distribution of pH') +
xlab('pH') +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p2 = ggplot(aes(x = alcohol), data = df_ww) +
geom_histogram(binwidth = 0.1, color = 'black', fill = '#099DD9') +
xlim(8,14.2) +
ggtitle('Distribution of Alcohol') +
xlab('Alcohol (% by volume)') +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
grid.arrange(p1,p2,ncol=1)
```
```{r}
summary(df_ww$pH)
summary(df_ww$alcohol)
```
Trough the plots we can see that the distribution curve of pH attribute is
normal with median in 3.18, mean in 3.188, 1st quartile in 3.09 and 3rd quartile
in 3.28. Alcohol curve however is positively skewed with median in 10.4, mean in
10.51. It is interesting that both plots don't present same distribution since
I've expected that alcohol content would be highly related to the pH. However,
the different distribution shapes show the opposite.
## Residual Sugar, chlorides and density
Finally, let's explore the remaining attributes distributions: residual sugar,
chlorides and density.
```{r echo=FALSE, message=FALSE, warning=FALSE}
p1 = ggplot(aes(x = residual.sugar), data = df_ww) +
geom_histogram(binwidth = 0.5, color = 'black', fill = '#099DD9') +
xlim(0.6,65.8) +
ggtitle('Distribution of Residual Sugar') +
xlab('Residual Sugar') +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p2 = ggplot(aes(x = chlorides), data = df_ww) +
geom_histogram(binwidth = 0.004, color = 'black', fill = '#099DD9') +
xlim(0.009,0.346) +
ggtitle('Distribution of Chlorides') +
xlab('Chlorides (% by volume)') +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p3 = ggplot(aes(x = density), data = df_ww) +
geom_histogram(binwidth = 0.0005, color = 'black', fill = '#099DD9') +
xlim(0.9871,1.039) +
ggtitle('Distribution of Density') +
xlab('Density (% by volume)') +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
grid.arrange(p1,p2,p3,ncol=1)
```
```{r}
summary(df_ww$residual.sugar)
summary(df_ww$chlorides)
summary(df_ww$density)
```
We can see that all attributes present a approximately normal distribution with
exception of residual sugar attribute. Residual sugar is highly positively
skewed causing median in 5.2 to diverge from mean in 6.391. In order to see
residual sugar behavior on others regions, let's rearrange our plot with a log
scale on x-axis.
```{r echo=FALSE, message=FALSE, warning=FALSE}
p1 = ggplot(aes(x = residual.sugar), data = df_ww) +
geom_histogram(binwidth = 1, color = 'black', fill = '#099DD9') +
xlim(0.6,65.8) +
ggtitle('Distribution of Residual Sugar with Continuous x Scale') +
xlab('Residual Sugar') +
ylab('Count') +
theme(plot.title = element_text(hjust = 0.5))
p2 = ggplot(aes(x = residual.sugar), data = df_ww) +
geom_histogram(binwidth = 0.035, color = 'black', fill = '#099DD9') +
ggtitle('Distribution of Residual Sugar with log10 x Scale') +
xlab('Residual Sugar') +
ylab('Count') +
scale_x_log10(breaks = c(seq(1,10),seq(20,100,10))) +
theme(plot.title = element_text(hjust = 0.5))
grid.arrange(p1,p2,ncol=1)
```
With log10 x scale it's possible to notice a bi-modal distribution with most
wines having residual sugar between 1 and 2 or between 7 and 15 showing that
some wines present higher sugar amount than others.
# Bivariate e Multivariate Plots Section
## Correlation Matrix
Before starting to analyse the bi-variate plots, let's produce the correlation
matrix using Pearson method in order to have initial correlation indexes between
attributes and to focus our multivariate analysis on those attributes.
```{r echo=FALSE, message=FALSE, warning=FALSE, include=TRUE, cache=FALSE}
ggcorr(df_ww[2:13], angle=90, hjust=0.15, label_size=3, label_round=2,
label=TRUE)
```
Through the matrix we can see strong correlations between some attributes. For
instance, density and alcohol present linear correlation of -0.78. Density and
residual sugar, linear correlation of 0.84. Quality and alcohol, linear
correlation of 0.43.
## Creating Sulphates and Residual Sugar buckets
In order to help in our multivariate exploration, let's bucket the residual
sugar and sulphates buckets so that we color others scatter plots attributes
using these buckets as references.
```{r}
df_ww$quality <- factor(df_ww$quality)
df_ww$sulphates.bucket <- cut(df_ww$sulphates, breaks=c(seq(0.2,1.1,0.2)))
df_ww$residual.sugar.bucket <- cut(df_ww$residual.sugar, breaks=c(seq(0,14,3)))
```
```{r}
str(df_ww$sulphates.bucket)
str(df_ww$residual.sugar.bucket)
```
## Density Exploration
Density is expected to have strong linear relationship with residual sugar and
alcohol, given that these last two attributes alter the wine water density.
Furthermore, according to the correlation matrix, density present linear
correlation coefficient of 0.84 with residual sugar and -0.78 with alcohol.
Let's produce scatter plots in order to visualize these relationships.
```{r echo=FALSE, message=FALSE, warning=FALSE}
p1 = ggplot(aes(x=residual.sugar, y=density), data=df_ww) +
geom_point(alpha=1/30) +
xlim(0,quantile(df_ww$residual.sugar,0.99)) +
ylim(quantile(df_ww$density,0), quantile(df_ww$density,0.99)) +
ggtitle('Density vs Residual Sugar') +
xlab(xlab(bquote('Residual Sugar ['~g/dm^3~ ']'))) +
ylab('Density ['~g/cm^3~ ']') +
theme(plot.title = element_text(hjust = 0.5)) +
geom_smooth()
p2 = ggplot(aes(x=alcohol, y=density), data=df_ww) +
geom_point(alpha=1/30) +
ylim(quantile(df_ww$density,0), quantile(df_ww$density,0.99)) +
ggtitle('Density vs Alcohol') +
xlab('Alcohol [% by volume]') +
ylab('Density ['~g/cm^3~ ']') +
theme(plot.title = element_text(hjust = 0.5)) +
geom_smooth()
grid.arrange(p1,p2,ncol=1)
```
As expected, density presents strong linear correlation with residual sugar and
alcohol. Given that these two factors acts directly in changing the water
density, due to chemical concepts, it's possible to say that density holds a
causation relationship with them.
## pH and Fixed Acidity Exploration
Also, through the matrix, we see a strong correlation index between pH and fixed
acidity. Again, chemical concepts support these relationship once acidity
influences the pH substance. Let's visualize it.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=fixed.acidity, y=pH), data=df_ww) +
geom_point(alpha=1/10) +
ggtitle('pH vs Fixed Acidity') +
xlab('Fixed Acidity') +
ylab('pH') +
theme(plot.title = element_text(hjust=0.5))
```
The linear correlation of -0.43 is confirmed and we notice that most wines have
pH between 3.0 and 3.3. Also, the relationship is not so strong as expected.
Maybe others attributes besides fixed acidity are influencing the wines pH.
First, let's see trough a scatter plot how sulphates effect the pH vs Fixed
Acidity distribution.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=fixed.acidity, y=pH), data=df_ww) +
geom_point(aes(color=sulphates.bucket), alpha=1/2) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Sulphates",
override.aes = list(alpha = 1,
size = 1))) +
ggtitle('pH vs Fixed Acidity') +
xlab('Fixed Acidity') +
ylab('pH') +
theme(plot.title = element_text(hjust=0.5))
```
It is hard to detect some pattern on how sulphates alter a pH wine. Trough the
previous plot it is not possible to find any tendency.
Proceeding with the pH vs fixed acidity exploration, let's now color our scatter
plot with the residual sugar attribute as reference.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=fixed.acidity,y=pH), data=df_ww) +
geom_point(aes(color=residual.sugar.bucket), alpha=1/3) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Residual Sugar",
override.aes = list(alpha = 1,
size = 1))) +
ggtitle('pH vs Fixed Acidity') +
xlab('Fixed Acidity') +
ylab('pH') +
theme(plot.title = element_text(hjust=0.5))
```
Through the previous plot, we see a tendency where wines with higher residual
sugar amount present lower pH (more acid). However this tendency is weak and we
can't see a clear pattern of how residual sugar influences the pH. This means
that in addition to the fixed acidity, residual sugar may be acting in a wine
pH, despite not having strong linear correlation.
## Quality Exploration
Now let's explore how wine quality relates with some attributes. First, as
detected by the correlation matrix, quality presents strong linear correlation
with alcohol. Let's visualize this relation in order to confirm it.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=quality, y=alcohol), data=df_ww) +
geom_jitter(alpha=.3) +
geom_boxplot( alpha = .5,color = 'blue')+
stat_summary(fun.y = "mean",
geom = "point",
color = "red",
shape = 8,
size = 2.5) +
ggtitle('Alcohol vs Quality') +
xlab('Quality') +
ylab('Alcohol') +
theme(plot.title = element_text(hjust=0.5))
```
In fact, we see that wines with more alcohol presence tend to be better reviewed
by the experts as the mean wine quality increase due to the linear correlation
coefficient of 0.44. We also see some discrepancy between mean and median for
wines with 5% and 8% alcohol volume due to the outliers found.
Carrying on with the quality exploration, let's visualize the relation with the
density, expecting to present strong correlation once the linear correlation
between them (provided by the correlation matrix) is -0.31 and also considering
that density correlates to alcohol, as showed in previous bi variate plots.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=quality, y=density), data=df_ww) +
geom_jitter(alpha=.2) +
geom_boxplot( alpha = .5,color = 'blue')+
stat_summary(fun.y = "mean",
geom = "point",
color = "red",
shape = 8,
size = 2.5) +
ggtitle('Density vs Quality') +
xlab('Quality') +
ylab('Density') +
ylim(quantile(df_ww$density, 0), quantile(df_ww$density, 0.99)) +
theme(plot.title = element_text(hjust=0.5))
```
We clearly can notice that density median tend to decrease as quality increases.
This confirms the strong linear correlation index of -0.31 between them and also
the correlation with alcohol.
Now, considering that chlorides also presented relatively strong linear
correlation with quality, let's plot this relationship in order to check if it
is confirmed.
```{r}
ggplot(aes(x=quality, y=chlorides), data=df_ww) +
geom_jitter(alpha=.2) +
geom_boxplot( alpha = .5,color = 'blue')+
stat_summary(fun.y = "mean",
geom = "point",
color = "red",
shape = 8,
size = 2.5) +
ylim(0,quantile(df_ww$chlorides,0.99)) +
ggtitle('Density vs Quality') +
xlab('Quality') +
ylab('Chlorides') +
theme(plot.title = element_text(hjust=0.5))
```
Again the visualization certified that chlorides is relatively strong correlated
(compared to others attributes) with linear correlation index of -0.21. We also
see trough medians and mean in the plot that, due to higher outliers, means are
higher than medians, as showed below.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=alcohol, y=density), data=df_ww) +
geom_point(aes(color=quality), alpha=1/3) +
ylim(quantile(df_ww$density,0),quantile(df_ww$density,0.99)) +
ggtitle('Density vs Alcohol') +
xlab('Alcohol') +
ylab('Density') +
theme(plot.title = element_text(hjust=0.5)) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Quality",
override.aes = list(alpha = 1,
size = 1)))
```
This plot show the interesting strong correlation between alcohol. It's easy to
notice that wine quality increases as alcohol volume increases and density
decreases. However, we see some outliers of good quality with low alcohol amount
and high density. Maybe others factors like residual sugar and fixed acidity also
influence in wine quality although not presenting strong linear correlation.
So, in order to explore which others factor make a high quality wine, let's
produce other plots replacing density by them.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=alcohol,y=residual.sugar), data=df_ww) +
geom_point(aes(color=quality), alpha=1/2) +
ylim(0,quantile(df_ww$residual.sugar,0.99)) +
ggtitle('Residual Sugar vs Alcohol') +
xlab('Alcohol') +
ylab('Residual Sugar') +
theme(plot.title = element_text(hjust=0.5)) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Quality",
override.aes = list(alpha = 1,
size = 1)))
```
Those outliers are still there with high residual sugar amount and low alcohol.
So residual sugar by itself doesn't explain them.
Let's see now volatile acidity.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=alcohol,y=volatile.acidity), data=df_ww) +
geom_point(aes(color=quality), alpha=1/2) +
ylim(0,quantile(df_ww$volatile.acidity,0.99)) +
ggtitle('Volatile Acidity vs Alcohol') +
xlab('Alcohol') +
ylab('Volatile Acidity') +
theme(plot.title = element_text(hjust=0.5)) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Quality",
override.aes = list(alpha = 1,
size = 1)))
```
This plot show a interesting slight tendency where wine with low volatile
acidity amount on lower alcohol present better quality.
```{r echo=FALSE, message=FALSE, warning=FALSE}
ggplot(aes(x=alcohol,y=total.sulfur.dioxide), data=df_ww) +
geom_point(aes(color=quality), alpha=1/2) +
ylim(quantile(df_ww$total.sulfur.dioxide,0),quantile(df_ww$total.sulfur.dioxide,0.99)) +
ggtitle('Total Sulfur Dioxide vs Alcohol') +
xlab('Alcohol') +
ylab('Total Sulfur Dioxide') +
theme(plot.title = element_text(hjust=0.5)) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Quality",
override.aes = list(alpha = 1,
size = 1)))
```
It is really difficult to find some pattern on total sulfur dioxide's influence
on wine quality. As detected by previous scatter multivariate plots, alcohol
strong correlates with wine quality, however we don't see clearly in the this
plot how total sulfur dioxide exactly acts on wine quality.
# Final Plots and Summary
### Plot One
```{r echo=FALSE, message=FALSE, warning=FALSE, Plot_One}
ggplot(aes(x=alcohol, y=quality), data=df_ww) +
geom_jitter(alpha=1/5) +
geom_smooth() +
ggtitle('Wine quality vs Alcohol') +
xlab('Alcohol [% by volume]') +
ylab('Wine quality') +
theme(plot.title = element_text(hjust=0.5))
```
### Description One
Through this plot we can see that wine quality strongly correlates with alcohol
amount. Quality tend to increase as alcohol increases. Moreover, according to
the correlation matrix produced previously on this report, alcohol is the
attribute that presents the most substantial correlation with quality wine.
### Plot Two
```{r echo=FALSE, message=FALSE, warning=FALSE, Plot_Two}
p1 = ggplot(aes(x=residual.sugar, y=density), data=df_ww) +
geom_point(alpha=1/30) +
xlim(0,quantile(df_ww$residual.sugar,0.99)) +
ylim(quantile(df_ww$density,0), quantile(df_ww$density,0.99)) +
ggtitle('Density vs Residual Sugar') +
xlab(xlab(bquote('Residual Sugar ['~g/dm^3~ ']'))) +
ylab('Density ['~g/cm^3~ ']') +
theme(plot.title = element_text(hjust = 0.5)) +
geom_smooth()
p2 = ggplot(aes(x=alcohol, y=density), data=df_ww) +
geom_point(alpha=1/30) +
ylim(quantile(df_ww$density,0), quantile(df_ww$density,0.99)) +
ggtitle('Density vs Alcohol') +
xlab('Alcohol [% by volume]') +
ylab('Density ['~g/cm^3~ ']') +
theme(plot.title = element_text(hjust = 0.5)) +
geom_smooth()
grid.arrange(p1,p2,ncol=1)
```
### Description Two
The correlation matrix also identified really strong correlations between
density and alcohol or residual sugar. In fact, this is expected given that
alcohol and residual sugar alter the water wine density due chemical concepts.
Visualizing this relationship on the previous plots, it is possible to confirm
the correlation showing that density tend to increase as residual sugar
increases or tend to decrease as alcohol increases.
### Plot Three
```{r echo=FALSE , message=FALSE, warning=FALSE, Plot_Three}
ggplot(aes(x=alcohol,y=volatile.acidity), data=df_ww) +
geom_point(aes(color=quality), alpha=1/2) +
ylim(0,quantile(df_ww$volatile.acidity,0.99)) +
scale_color_brewer(type = 'qual',
guide = guide_legend(title = "Quality",
override.aes = list(alpha = 1,
size = 1))) +
ggtitle('Volatile acidity vs Alcohol') +
xlab('Alcohol [% by volume]') +
ylab('Volatile Acidity ['~g/dm^3~ ']') +
theme(plot.title = element_text(hjust = 0.5))
```
### Description Three
Again we see the relevant correlation between alcohol and quality, however this
plot also show a slight tendency where quality tend to increase as volatile
acidity decreases at lower alcohol volumes amounts. This fact shows that,
besides alcohol, others attributes contribute to the wine quality and when mixed
may determine a high quality wine.
------
# Reflection
The data set provided by Cortez et al. (2009) contains attributes of 4,898 white
wines. With this data collection it was possible to explore how this chemical
attributes correlate between them and also how they impact in a white wine
quality. Each wine was reviewed by experts with grades between 1 and 10.
Initially, the exploration approached the attributes distribution with
uni-variate histogram plots aid. Most attributes presented normal distribution
with residual sugar exception. After that, through the matrix correlation and
bi-variate scatter plots, the correlations between the attributes were analyzed.
Some chemical concepts were confirmed by really strong correlations, as density
depending on residual sugar and alcohol. Also, still on bi-variate analysis, it
was surprising to discover that alcohol produced the highest correlation with
quality wine. It was really hard to detect some pattern in correlation between
wine quality and other attributes, but thanks to multivariate scatter plots, it
was possible to notice that other attributes also acts on wine quality. Volatile
acidity contributes in a higher wine quality given that low volatile acidity
tends to increase quality. However, others multivariate plots failed in showing
strong patterns and correlation and was not possible to gather some insights and
resolutions trough them. Thinking in future works, this data set could be
pontentialized with more wine attributes observations so that a quality
prediction model could be made using machine learning techniques.
# References
P. Cortez, A. Cerdeira, F. Almeida, T. Matos and J. Reis.
Modeling wine preferences by data mining from physicochemical properties.
In Decision Support Systems, Elsevier, 47(4):547-553. ISSN: 0167-9236.