-
Notifications
You must be signed in to change notification settings - Fork 0
/
The-Truth-about-Vinho-Verde-Wines-17165628.R
1547 lines (1280 loc) · 66.1 KB
/
The-Truth-about-Vinho-Verde-Wines-17165628.R
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
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#SOURCES
#######################################################################################################
#######################################################################################################
#wine-quality-red https://www.openml.org/d/40691
#wine-quality-white https://www.openml.org/d/40498
#LIBRARIES NEEDED
#######################################################################################################
#######################################################################################################
library(tidyverse) #tidiversey contains other packages as
library(tidyr)
library(tibble)
library(ggplot2) #graphics
library(readr) #library to read csv
library(dplyr)
library(openintro)
library(tools)
library(GGally)
library(forcats)
library(ggpubr)
library(mvShapiroTest)
library(gridExtra)
library(moments)
library(cowplot) #add different plots together
library(nortest) # to be able to perform Anderson-Darling normality test
library(rstatix)
library(FSA) #Dunn Test
library(ggcorrplot) #correlation matrix
library(rpart)
library(rpart.plot)
library(caret)
library(e1071)
library(randomForest)
library(gdata)
library(DiagrammeR)
#IMPORTING DATA SETS
#######################################################################################################
#######################################################################################################
redwine <- read.csv("wine-quality-red.csv", head=TRUE, sep=",")
whitewine <- read.csv("wine-quality-white.csv", head=TRUE, sep=",")
#DATA SET EXPLORATION
#######################################################################################################
#######################################################################################################
#Check the number of rows of each data set
nrow(redwine)
nrow(whitewine)
#Check first rows of each of the data sets
head(redwine)
head(whitewine)
#Check the last rows of each of the data sets
tail(redwine)
tail(whitewine)
#Information: Number of observations. Number of valiables.
#Variables name and class, as well as some of the data for each of them.
str(redwine)
str(whitewine)
#Check only names of variables for each of the data sets
names(redwine) #class variable will be more meaningful with the name quality
names(whitewine) #We will need to change the names so are the same as in the other data set
#Check if the data sets has any missing value
redwine[!complete.cases(redwine), ] #no missing rows
whitewine[!complete.cases(whitewine), ] #no missing rows
#CLEANING DATA / DATA TRANSFORMATION
#######################################################################################################
#######################################################################################################
#Renaming both files with same variable names
redwine_renamed <- redwine %>% rename("quality" = "class",
"ph" = "pH")
whitewine_renamed <- whitewine %>% rename(
"fixed_acidity" = "V1",
"volatile_acidity" = "V2",
"citric_acid" = "V3",
"residual_sugar" = "V4",
"chlorides" = "V5",
"free_sulfur_dioxide" = "V6",
"total_sulfur_dioxide" = "V7",
"density" = "V8",
"ph" = "V9",
"sulphates" = "V10",
"alcohol" = "V11",
"quality" = "Class")
#Check the names of variables again to ensure they were changed
names(redwine_renamed)
names(whitewine_renamed)
#Changing "Quality" from integer to factor with ordered levels
#######################################################################################################
#Checking current class of variable
class(redwine_renamed$quality)
#Changing quality from character to factor
redwine_renamed <- mutate_at(redwine_renamed,vars(quality), as.factor)
#Adding levels to factor
redwine_renamed$quality <- factor(redwine_renamed$quality, levels = c("1","2","3","4","5","6","7","8","9","10"))
#Check if the variable is now a factor with levels
class(redwine_renamed$quality)
levels(redwine_renamed$quality)
#Checking current class of variable
class(whitewine_renamed$quality)
#Changing quality from character to factor
whitewine_renamed <- mutate_at(whitewine_renamed,vars(quality), as.factor)
#Adding levels to factor
whitewine_renamed$quality <- factor(whitewine_renamed$quality, levels = c("1","2","3","4","5","6","7","8","9","10"))
#Check if the variable is now a factor with levels
class(whitewine_renamed$quality)
levels(whitewine_renamed$quality)
#Creating new variable "Type" which will include if the wine is red or white and changing it from character to factor
#######################################################################################################
#New variable for red wine
redwine_renamed["type"] = "red"
#Checking class of new variable
class(redwine_renamed$type)
#Change from character to factor
redwine_renamed <- mutate_at(redwine_renamed, vars(type), as.factor)
#Check if the variable is now a factor
class(redwine_renamed$type)
#New variable for white wine
whitewine_renamed["type"] = "white"
#checking class of new variable
class(whitewine_renamed$type)
#Change from character to factor
whitewine_renamed <- mutate_at(whitewine_renamed, vars(type), as.factor)
#Check if the variable is now a factor
class(whitewine_renamed$type)
#Creating new valiable "Type by Sugar Level", which will help understanding the data set better
#######################################################################################################
#Following the guidance of https://en.wikipedia.org/wiki/Sweetness_of_wine
#Creating new variable Type by Sugar Level in red wine set
redwine_renamed <- redwine_renamed %>%
add_column(type_by_sugar_level = ifelse (redwine_renamed$residual_sugar <= 4 ,"Dry",
ifelse (redwine_renamed$residual_sugar >4 & redwine_renamed$residual_sugar <=12,"Medium Dry",
ifelse (redwine_renamed$residual_sugar >12 & redwine_renamed$residual_sugar <=45,"Medium","Sweet"))))
#Chaning new variable from character to factor
redwine_renamed <- mutate_at(redwine_renamed, vars(type_by_sugar_level), as.factor)
#Adding ordered levels to factor variable
redwine_renamed$type_by_sugar_level <- factor(redwine_renamed$type_by_sugar_level, levels = c("Dry","Medium Dry","Medium","Sweet"))
#Check if the variable is now a factor with levels
class(redwine_renamed$type_by_sugar_level)
levels(redwine_renamed$type_by_sugar_level)
#Checking number of samples inside each of the newest created variable
redwine_renamed %>%
group_by(redwine_renamed$type_by_sugar_level) %>%
summarise(n = n())
#Creating new variable Type by Sugar Level in white wine set
whitewine_renamed <- whitewine_renamed %>%
add_column(type_by_sugar_level =ifelse (whitewine_renamed$residual_sugar <=4,"Dry",
ifelse (whitewine_renamed$residual_sugar >4 & whitewine_renamed$residual_sugar <=12,"Medium Dry",
ifelse (whitewine_renamed$residual_sugar >12 & whitewine_renamed$residual_sugar <=45,"Medium","Sweet"))))
#Chaning new variable from character to factor
whitewine_renamed <- mutate_at(whitewine_renamed, vars(type_by_sugar_level), as.factor)
#Adding ordered levels to factor variable
whitewine_renamed$type_by_sugar_level <- factor(whitewine_renamed$type_by_sugar_level, levels = c("Dry","Medium Dry","Medium","Sweet"))
#Check if the variable is now a factor with levels
class(whitewine_renamed$type_by_sugar_level)
levels(whitewine_renamed$type_by_sugar_level)
#Checking number of samples inside each of the newest created variable
whitewine_renamed %>%
group_by(whitewine_renamed$type_by_sugar_level) %>%
summarise(n = n())
#Creating new valiable numerical variable "Total Acidity", which will help understanding the data set better
#######################################################################################################
#Creating new variable Total Acidity for red wine
redwine_renamed <- redwine_renamed %>%
mutate(total_acitity = fixed_acidity + volatile_acidity)
#Checking the variable was created
head(redwine_renamed)
#Checking the class is numeric
class(redwine_renamed$total_acitity)
#Creating new variable Total Acidity for white wine
whitewine_renamed <- whitewine_renamed %>%
mutate(total_acitity = fixed_acidity + volatile_acidity)
#Checking the variable was created
head(whitewine_renamed)
#Checking the class is numeric
class(whitewine_renamed$total_acitity)
#Creating new variable "PH Level" as factor with levels
#######################################################################################################
#Creating new variable for red wine
redwine_renamed <- redwine_renamed %>%
add_column(ph_level = ifelse (redwine_renamed$ph <= 2.8 ,"PH<=2.8",
ifelse (redwine_renamed$ph >2.8 & redwine_renamed$ph <=3,"2.8>PH<=3",
ifelse (redwine_renamed$ph >3 & redwine_renamed$ph <=3.5,"3>PH<=3.5",
ifelse (redwine_renamed$ph >3.5 & redwine_renamed$ph <=4,"3>PH<=4", "PH>4")))))
#Checking class for new variable
class(redwine_renamed$ph_level)
#Change from character to factor
redwine_renamed <- mutate_at(redwine_renamed, vars(ph_level), as.factor)
#Add levels to the factor
redwine_renamed$ph_level <- factor(redwine_renamed$ph_level, levels = c("PH<=2.8","2.8>PH<=3","3>PH<=3.5","3>PH<=4","PH>4"))
#Check class again to confirm is a factor
class(redwine_renamed$ph_level)
#Check levels of factor
levels(redwine_renamed$ph_level)
#Check number of samples for each type of PH category
redwine_renamed %>%
group_by(redwine_renamed$ph_level) %>%
summarise(n = n())
#Creating new variable for white wine
whitewine_renamed <- whitewine_renamed %>%
add_column(ph_level = ifelse (whitewine_renamed$ph <= 2.8 ,"PH<=2.8",
ifelse (whitewine_renamed$ph >2.8 & whitewine_renamed$ph <=3,"2.8>PH<=3",
ifelse (whitewine_renamed$ph >3 & whitewine_renamed$ph <=3.5,"3>PH<=3.5",
ifelse (whitewine_renamed$ph >3.5 & whitewine_renamed$ph <=4,"3>PH<=4", "PH>4")))))
#Checking class for new variable
class(whitewine_renamed$ph_level)
#Change from character to factor
whitewine_renamed <- mutate_at(whitewine_renamed, vars(ph_level), as.factor)
#Add levels to the factor
whitewine_renamed$ph_level <- factor(whitewine_renamed$ph_level, levels = c("PH<=2.8","2.8>PH<=3","3>PH<=3.5","3>PH<=4","PH>4"))
#Check class again to confirm is a factor
class(whitewine_renamed$ph_level)
#Check levels of factor
levels(whitewine_renamed$ph_level)
#Check number of samples for each type of PH category
whitewine_renamed %>%
group_by(whitewine_renamed$ph_level) %>%
summarise(n = n())
#Creating new variable "Alcohol Level" as factor with levels
#######################################################################################################
#Following https://www.realsimple.com/holidays-entertaining/entertaining/food-drink/alcohol-content-wine
#Creating new variable for red wine
redwine_renamed <- redwine_renamed %>%
add_column(alcohol_level = ifelse (redwine_renamed$alcohol <= 12.5 ,"Very Low",
ifelse (redwine_renamed$alcohol >12.5 & redwine_renamed$alcohol <=13.5,"Moderately Low",
ifelse (redwine_renamed$alcohol >13.5 & redwine_renamed$alcohol <=14.5,"High", "Very High"))))
#Checking class for new variable
class(redwine_renamed$alcohol_level)
#Change from character to factor
redwine_renamed <- mutate_at(redwine_renamed, vars(alcohol_level), as.factor)
#Add levels to the factor
redwine_renamed$alcohol_level <- factor(redwine_renamed$alcohol_level, levels = c("Very Low","Moderately Low","High","Very High"))
#Check class again to confirm is a factor
class(redwine_renamed$alcohol_level)
#Check levels of factor
levels(redwine_renamed$alcohol_level)
#Check number of samples for each type of PH category
redwine_renamed %>%
group_by(redwine_renamed$alcohol_level) %>%
summarise(n = n())
#Creating new variable for white wine
whitewine_renamed <- whitewine_renamed %>%
add_column(alcohol_level = ifelse (whitewine_renamed$alcohol <= 12.5 ,"Very Low",
ifelse (whitewine_renamed$alcohol >12.5 & whitewine_renamed$alcohol <=13.5,"Moderately Low",
ifelse (whitewine_renamed$alcohol >13.5 & whitewine_renamed$alcohol <=14.5,"High", "Very High"))))
#Checking class for new variable
class(whitewine_renamed$alcohol_level)
#Change from character to factor
whitewine_renamed <- mutate_at(whitewine_renamed, vars(alcohol_level), as.factor)
#Add levels to the factor
whitewine_renamed$alcohol_level <- factor(whitewine_renamed$alcohol_level, levels = c("Very Low","Moderately Low","High","Very High"))
#Check class again to confirm is a factor
class(whitewine_renamed$alcohol_level)
#Check levels of factor
levels(whitewine_renamed$alcohol_level)
#Check number of samples for each type of PH category
whitewine_renamed %>%
group_by(whitewine_renamed$alcohol_level) %>%
summarise(n = n())
#CLEAN DATA CHECK
#######################################################################################################
#######################################################################################################
str(redwine_renamed)
str(whitewine_renamed)
#Summary as all the variables are numerical, informs about Minimun Value, 1st Quartile, Median, Mean, 3rd Quartile and Maximum Value for each of the variables.
summary(redwine_renamed)
summary(whitewine_renamed)
#COMBINE DATA SETS
#######################################################################################################
#######################################################################################################
#Combine both data sets
head(redwine_renamed)
head(whitewine_renamed)
winequality <- rbind(redwine_renamed,whitewine_renamed)
as.data.frame(winequality)
head(winequality)
tail(winequality)
#ABOUT THE DATA
#######################################################################################################
#######################################################################################################
#Create bar plot for red and white wines based on "Quality"
data_quality <- ggplot(winequality, aes(x = quality)) +
labs(title = "Quality of wines", x = "Quality",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#Create bar plot for red and white wines based on "Total Acidity"
data_total_acidity <- ggplot(winequality, aes(x = total_acitity)) +
labs(title = "Total Acidity (g/l) in wines",x = "Total Acidity (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5, binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Volatile Acidity"
data_volatile_acidity <- ggplot(winequality, aes(x = volatile_acidity)) +
labs(title = "Volatile Acidity (g/l) in wines",x = "Volatile Acidity (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Fixed Acidity"
data_fixed_acidity <- ggplot(winequality, aes(x = fixed_acidity)) +
labs(title = "Fixed Acidity (g/l) in wines",x = "Fixed Acidity (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "PH Level"
data_ph_level <- ggplot(winequality, aes(x = ph_level)) +
labs(title = "pH Level in wines", x="pH Level",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5)+
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#Create bar plot for red and white wines based on "Sulphates"
data_sulphates <- ggplot(winequality, aes(x = sulphates)) +
labs(title = "Sulphates (g/l) in wines",x = "Sulphates (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Total Sulfur Dioxide"
data_total_sulfur_dioxide <- ggplot(winequality, aes(x = total_sulfur_dioxide)) +
labs(title = "Total Sulfur Dioxide in wines",x = "Total Sulfur Dioxide (mg/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Free Sulfur Dioxide"
data_free_sulfur_dioxide <- ggplot(winequality, aes(x = free_sulfur_dioxide)) +
labs(title = "Free Sulfur Dioxide (mg/l) in wines",x = "Free Sulfur Dioxide (mg/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#Create bar plot for red and white wines based on "Alcohol Level"
data_alcohol<- ggplot(winequality, aes(x = alcohol_level)) +
labs(title = "Alcohol Level (%) in wines", x="Alcohol Level (%)",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5)+
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Density"
data_density <- ggplot(winequality, aes(x = density)) +
labs(title = "Density (g/ml) in wines", x = "Density (g/ml)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.001) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Residual Sugar Level"
data_sugar_level <- ggplot(winequality, aes(x = type_by_sugar_level)) +
labs(title = "Type of wine by Sugar Level", x = "Type by Sugar Level",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for red and white wines based on "Chlorides"
data_chlorides <- ggplot(winequality, aes(x = chlorides)) +
labs(title = "Chlorides in wines", x = "Chlorides",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#After creating all the different bar plots for each of the variables I add some of them together for better visualisation
data_quality
plot_grid(data_total_acidity,data_ph_level, nrow = 1)
plot_grid(data_fixed_acidity, data_volatile_acidity, nrow = 1)
data_sulphates
plot_grid(data_total_sulfur_dioxide,data_free_sulfur_dioxide)
plot_grid(data_sugar_level,data_alcohol, nrow = 1)
plot_grid(data_density,data_chlorides, nrow = 1)
#CREATING SUBSET WITH ONLY DRY WINES
#######################################################################################################
#######################################################################################################
#Subset the combined data set and chose just dry wines
winequality_dry <- subset(winequality, winequality$type_by_sugar_level =="Dry")
#Subset the red wine data set
redwine_renamed_dry <- subset(redwine_renamed, redwine_renamed$type_by_sugar_level == "Dry")
#Subset the red wine data set
whitewine_renamed_dry <- subset(whitewine_renamed, whitewine_renamed$type_by_sugar_level == "Dry")
#information about new data sets
str(winequality_dry)
str(redwine_renamed_dry)
str(whitewine_renamed_dry)
#ABOUT DRY VINHO VERDE
#######################################################################################################
#######################################################################################################
#Create bar plot for dry red and white wines based on "Quality"
data_quality_dry <- ggplot(winequality_dry, aes(x = quality)) +
labs(title = "Quality of dry wines", x = "Quality",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#Create bar plot for dry red and white wines based on "Total Acidity"
data_total_acidity_dry <- ggplot(winequality_dry, aes(x = total_acitity)) +
labs(title = "Total Acidity (g/l) in dry wines",x = "Total Acidity (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5, binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Volatile Acidity"
data_volatile_acidity_dry <- ggplot(winequality_dry, aes(x = volatile_acidity)) +
labs(title = "Volatile Acidity (g/l) in dry wines",x = "Volatile Acidity (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Fixed Acidity"
data_fixed_acidity_dry <- ggplot(winequality_dry, aes(x = fixed_acidity)) +
labs(title = "Fixed Acidity (g/l) in dry wines",x = "Fixed Acidity (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "PH Level"
data_ph_level_dry <- ggplot(winequality_dry, aes(x = ph_level)) +
labs(title = "pH Level in wines", x="pH Level",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5)+
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#Create bar plot for dry red and white wines based on "Sulphates"
data_sulphates_dry <- ggplot(winequality_dry, aes(x = sulphates)) +
labs(title = "Sulphates (g/l) in dry wines",x = "Sulphates (g/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Total Sulfur Dioxide"
data_total_sulfur_dioxide_dry <- ggplot(winequality_dry, aes(x = total_sulfur_dioxide)) +
labs(title = "Total Sulfur Dioxide in dry wines",x = "Total Sulfur Dioxide (mg/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Free Sulfur Dioxide"
data_free_sulfur_dioxide_dry <- ggplot(winequality_dry, aes(x = free_sulfur_dioxide)) +
labs(title = "Free Sulfur Dioxide (mg/l) in dry wines",x = "Free Sulfur Dioxide (mg/l)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#Create bar plot for dry red and white wines based on "Alcohol Level"
data_alcohol_dry<- ggplot(winequality_dry, aes(x = alcohol_level)) +
labs(title = "Alcohol Level (%) in wines", x="Alcohol Level (%)",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5)+
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Density"
data_density_dry <- ggplot(winequality_dry, aes(x = density)) +
labs(title = "Density (g/ml) in wines", x = "Density (g/ml)",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.001) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Residual Sugar Level"
data_sugar_level_dry <- ggplot(winequality_dry, aes(x = type_by_sugar_level)) +
labs(title = "Type of wine by Sugar Level", x = "Type by Sugar Level",y="Count",fill="Type")+
geom_bar(aes(fill = type), alpha = 0.5) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#
#Create bar plot for dry red and white wines based on "Chlorides"
data_chlorides_dry <- ggplot(winequality_dry, aes(x = chlorides)) +
labs(title = "Chlorides in wines", x = "Chlorides",y="Count",fill="Type")+
geom_histogram(aes(fill = type), alpha = 0.5,binwidth = 0.1) +
scale_color_manual(values = c("#990000","#CCCC00"))+
scale_fill_manual(values = c("#990000","#CCCC00"))+
theme(plot.title = element_text(hjust = 0.5))
#After creating all the different bar plots for each of the variables I add some of them together for better visualisation
data_quality_dry
plot_grid(data_total_acidity_dry,data_ph_level_dry, nrow = 1)
plot_grid(data_fixed_acidity_dry, data_volatile_acidity_dry, nrow = 1)
data_sulphates_dry
plot_grid(data_total_sulfur_dioxide_dry,data_free_sulfur_dioxide_dry)
plot_grid(data_sugar_level_dry,data_alcohol_dry, nrow = 1)
plot_grid(data_density_dry,data_chlorides_dry, nrow = 1)
#TESTING NORMALITY
#######################################################################################################
#######################################################################################################
#qq plots for numerical variables red wine
qq_red_fixed_acidity <- ggqqplot(redwine_renamed$fixed_acidity, color = "#990000")+
labs(x="Theoretical Fixed Acidity", y="Sample Fixed Acidity")
qq_red_citric_acid <- ggqqplot(redwine_renamed$citric_acid, color = "#990000")+
labs(x="Theoretical Citric Acid", y="Sample Citric Acid")
qq_red_volatile_acidity <- ggqqplot(redwine_renamed$volatile_acidity, color = "#990000")+
labs(x="Theoretical Volatile Acidity", y="Sample Volatile Acidity")
qq_red_total_acidity <- ggqqplot(redwine_renamed$total_acitity, color = "#990000")+
labs(x="Theoretical Total Acidity", y="Sample Total Acidity")
qq_red_ph <- ggqqplot(redwine_renamed$ph, color = "#990000")+
labs(x="Theoretical PH", y="Sample PH")
qq_red_residual_sugar <- ggqqplot(redwine_renamed$residual_sugar, color = "#990000")+
labs(x="Theoretical Residual Sugar", y="Sample Residual Sugar")
qq_red_alcohol <- ggqqplot(redwine_renamed$alcohol, color = "#990000")+
labs(x="Theoretical Alcohol", y="Sample Alcohol")
qq_red_density <- ggqqplot(redwine_renamed$density, color = "#990000")+
labs(x="Theoretical Density", y="Sample Density")
qq_red_chlorides <- ggqqplot(redwine_renamed$chlorides, color = "#990000")+
labs(x="Theoretical Chlorides", y="Sample Chlorides")
qq_red_free_sulfur_dioxide <- ggqqplot(redwine_renamed$free_sulfur_dioxide, color = "#990000")+
labs(x="Theoretical Free Sulphur Dioxide", y="Sample Free Sulphur Dioxide")
qq_red_total_sulfur_dioxide <- ggqqplot(redwine_renamed$total_sulfur_dioxide, color = "#990000")+
labs(x="Theoretical Total Sulphur Dioxide", y="Sample Total Sulphur Dioxide")
qq_red_sulphates <- ggqqplot(redwine_renamed$sulphates, color = "#990000")+
labs(x="Theoretical Sulphates", y="Sample Sulphates")
#After creating all the different qq plots for each of the variables we add them together for better visualisation
grid.arrange(qq_red_total_acidity, qq_red_fixed_acidity,qq_red_citric_acid, qq_red_volatile_acidity,
qq_red_ph, qq_red_sulphates, qq_red_free_sulfur_dioxide, qq_red_total_sulfur_dioxide,
qq_red_residual_sugar, qq_red_alcohol, qq_red_density, qq_red_chlorides)
#qq plots for numerical variables white wine
qq_white_fixed_acidity <- ggqqplot(whitewine_renamed$fixed_acidity, color = "#CCCC00")+
labs(x="Theoretical Fixed Acidity", y="Sample Fixed Acidity")
qq_white_citric_acid <- ggqqplot(whitewine_renamed$citric_acid, color = "#CCCC00")+
labs(x="Theoretical Citric Acid", y="Sample Citric Acid")
qq_white_volatile_acidity <- ggqqplot(whitewine_renamed$volatile_acidity, color = "#CCCC00")+
labs(x="Theoretical Volatile Acidity", y="Sample Volatile Acidity")
qq_white_total_acidity <- ggqqplot(whitewine_renamed$total_acitity, color = "#CCCC00")+
labs(x="Theoretical Total Acidity", y="Sample Total Acidity")
qq_white_ph <- ggqqplot(whitewine_renamed$ph, color = "#CCCC00")+
labs(x="Theoretical PH", y="Sample PH")
qq_white_residual_sugar <- ggqqplot(whitewine_renamed$residual_sugar, color = "#CCCC00")+
labs(x="Theoretical Residual Sugar", y="Sample Residual Sugar")
qq_white_alcohol <- ggqqplot(whitewine_renamed$alcohol, color = "#CCCC00")+
labs(x="Theoretical Alcohol", y="Sample Alcohol")
qq_white_density <- ggqqplot(whitewine_renamed$density, color = "#CCCC00")+
labs(x="Theoretical Density", y="Sample Density")
qq_white_chlorides <- ggqqplot(whitewine_renamed$chlorides, color = "#CCCC00")+
labs(x="Theoretical Chlorides", y="Sample Chlorides")
qq_white_free_sulfur_dioxide <- ggqqplot(whitewine_renamed$free_sulfur_dioxide, color = "#CCCC00")+
labs(x="Theoretical Free Sulphur Dioxide", y="Sample Free Sulphur Dioxide")
qq_white_total_sulfur_dioxide <- ggqqplot(whitewine_renamed$total_sulfur_dioxide, color = "#CCCC00")+
labs(x="Theoretical Total Sulphur Dioxide", y="Sample Total Sulphur Dioxide")
qq_white_sulphates <- ggqqplot(whitewine_renamed$sulphates, color = "#CCCC00")+
labs(x="Theoretical Sulphates", y="Sample Sulphates")
#After creating all the different qq plots for each of the variables we add them together for better visualisation
grid.arrange(qq_white_total_acidity, qq_white_fixed_acidity,qq_white_citric_acid, qq_white_volatile_acidity,
qq_white_ph, qq_white_sulphates, qq_white_free_sulfur_dioxide, qq_white_total_sulfur_dioxide,
qq_white_residual_sugar, qq_white_alcohol, qq_white_density, qq_white_chlorides)
str(redwine_renamed_dry)
#Shapiro-Wilk normality test
#create variable so we can run the test just for the numerical values
x <- c(1:11,15)
#Red wine
for (i in x) {
print(shapiro.test(redwine_renamed_dry[, i]))
}
#White wine
for (i in x) {
print(shapiro.test(whitewine_renamed_dry[, i]))
}
#CORRELATIONS (https://www.dataquest.io/blog/statistical-learning-for-predictive-modeling-r/)
#######################################################################################################
#######################################################################################################
#Correlation dry red wines
#
x <- c(1:11,15)
#
#Spearman Correlations
corr_spearman_redwine_renamed_dry <- round(cor(redwine_renamed_dry[,x], method = "spearman"), 2)
corr_spearman_redwine_renamed_dry
#
#Kendall Correlations
corr_kendall_redwine_renamed_dry <- round(cor(redwine_renamed_dry[,x], method = "kendall"), 2)
corr_kendall_redwine_renamed_dry
#
#correlation matrix: Spearman Correlations
plot_corr_spearman_redwine_renamed_dry <- ggcorrplot(corr_spearman_redwine_renamed_dry,
hc.order = TRUE,
type = "lower",
lab = TRUE,
colors = c("#202020","white","#FF0000"))+
labs (title = "Spearman Correlation Coeficients")+
theme(plot.title = element_text(hjust = 0.5))
#
#correlation matrix: Kendall Correlations
plot_corr_kendall_redwine_renamed_dry <- ggcorrplot(corr_kendall_redwine_renamed_dry,
hc.order = TRUE,
type = "lower",
lab = TRUE,
colors = c("#202020","white","#FF0000"))+
labs (title = "Kendall Correlation Coeficients")+
theme(plot.title = element_text(hjust = 0.5))
#Combining both matrix
grid.arrange(plot_corr_spearman_redwine_renamed_dry, plot_corr_kendall_redwine_renamed_dry, nrow=1)
#Correlation dry white wines
#
x <- c(1:11,15)
#
#Spearman Correlations
corr_spearman_whitewine_renamed_dry <- round(cor(whitewine_renamed_dry[,x], method = "spearman"), 2)
corr_spearman_whitewine_renamed_dry
#
#Kendall Correlations
corr_kendall_whitewine_renamed_dry <- round(cor(whitewine_renamed_dry[,x], method = "kendall"), 2)
corr_kendall_whitewine_renamed_dry
#
#correlation matrix: Spearman Correlations
plot_corr_spearman_whitewine_renamed_dry <- ggcorrplot(corr_spearman_whitewine_renamed_dry,
hc.order = TRUE,
type = "lower",
lab = TRUE,
colors = c("#FFFF33","white","#CCCC00"))+
labs (title = "Spearman Correlation Coeficients")+
theme(plot.title = element_text(hjust = 0.5))
#
#correlation matrix: Kendall Correlations
plot_corr_kendall_whitewine_renamed_dry <- ggcorrplot(corr_kendall_whitewine_renamed_dry,
hc.order = TRUE,
type = "lower",
lab = TRUE,
colors = c("#FFFF33","white","#CCCC00"))+
labs (title = "Kendall Correlation Coeficients")+
theme(plot.title = element_text(hjust = 0.5))
#Combining both matrix
grid.arrange(plot_corr_spearman_whitewine_renamed_dry, plot_corr_kendall_whitewine_renamed_dry, nrow=1)
#INSIGHT 1 - IS THERE ANY DIFFERENCE BETWEEN DRY RED AND WHITE VINHO VERDE WINES
#BASED ON THEIR CHEMICAL PROPERTIES?
#######################################################################################################
#######################################################################################################
#Subset by just dry wines with quality 5
winequality_dry_5 <- subset(winequality_dry, winequality_dry$quality == "5")
redwine_renamed_dry_5 <- subset(redwine_renamed_dry, redwine_renamed_dry$quality == "5")
whitewine_renamed_dry_5 <- subset(whitewine_renamed_dry, whitewine_renamed_dry$quality == "5")
#Descriptive Statistics
#Creationg of function which will give more information than summary function does
#Same as function created in class with kurtosis
Stats <- function(stats){
newMatrix <- matrix(1:8, nrow=1) #creating a blank matrix
colnames(newMatrix) <- c("Mean","Median","Variance","Standard Deviation","Minimum","Maximum","Skewness","Kurtosis")
rownames(newMatrix) <- "Stats"
newMatrix[1, ] <- c(mean(stats),median(stats),var(stats),sd(stats),min(stats),max(stats),skewness(stats),kurtosis(stats))
newMatrix
}
#Using stats for both subsets
#
x <- c(1:11,15)
#
for (i in x) {
print(Stats(redwine_renamed_dry_5[, i]))
}
#
for (i in x) {
print(Stats(whitewine_renamed_dry_5[, i]))
}
#Density plots
#
#Fixed Acidity
density_red_white_fixed_acidity <- ggplot(winequality_dry_5, aes(x = fixed_acidity, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(fixed_acidity)),
color="black", linetype="dashed", size=1)+
labs (x = "Fixed Acidity (g/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Volatile Acidity
density_red_white_volatile_acidity <- ggplot(winequality_dry_5, aes(x = volatile_acidity, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(volatile_acidity)),
color="black", linetype="dashed", size=1)+
labs (x = "Volatile Acidity (g/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Citric Acid
density_red_white_citric_acid <- ggplot(winequality_dry_5, aes(x = citric_acid, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(citric_acid)),
color="black", linetype="dashed", size=1)+
labs (x = "Citric Acid (g/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Residual Sugar
density_red_white_residual_sugar <- ggplot(winequality_dry_5, aes(x = residual_sugar, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(residual_sugar)),
color="black", linetype="dashed", size=1)+
labs (x = "Residual Sugar (g/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Chlorides
density_red_white_chlorides <- ggplot(winequality_dry_5, aes(x = chlorides, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(chlorides)),
color="black", linetype="dashed", size=1)+
labs (x = "Chlorides", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Free Sulphur Dioxide
density_red_white_free_sulfur_dioxide <- ggplot(winequality_dry_5, aes(x = free_sulfur_dioxide, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(free_sulfur_dioxide)),
color="black", linetype="dashed", size=1)+
labs (x = "Free Sulphur Dioxide (mg/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Total Sulphur Dioxide
density_red_white_total_sulfur_dioxide <- ggplot(winequality_dry_5, aes(x = total_sulfur_dioxide, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(total_sulfur_dioxide)),
color="black", linetype="dashed", size=1)+
labs (x = "Total Sulphur Dioxide (mg/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Density
density_red_white_density <- ggplot(winequality_dry_5, aes(x = density, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(density)),
color="black", linetype="dashed", size=1)+
labs (x = "Density (g/ml)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#PH
density_red_white_ph <- ggplot(winequality_dry_5, aes(x = ph, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(ph)),
color="black", linetype="dashed", size=1)+
labs (x = "PH", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Sulphates
density_red_white_sulphates <- ggplot(winequality_dry_5, aes(x = sulphates, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(sulphates)),
color="black", linetype="dashed", size=1)+
labs (x = "Sulphates (g/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Alcohol
density_red_white_alcohol <- ggplot(winequality_dry_5, aes(x = alcohol, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(alcohol)),
color="black", linetype="dashed", size=1)+
labs (x = "Alcohol (%)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#
#Total Acidity
density_red_white_total_acidity <- ggplot(winequality_dry_5, aes(x = total_acitity, color = type)) +
geom_density()+
geom_vline(aes(xintercept=mean(total_acitity)),
color="black", linetype="dashed", size=1)+
labs (x = "Total Acidity (mg/l)", y = "Density", color = "Type")+
scale_color_manual(values=c("#990000","#CCCC00"))
#After creating each of the density plots we add them all together for easier visualisation
plot_grid(density_red_white_fixed_acidity, density_red_white_citric_acid, density_red_white_volatile_acidity,
density_red_white_total_acidity, labels = "AUTO", ncol = 2)
#
plot_grid(density_red_white_ph,density_red_white_residual_sugar, density_red_white_alcohol,
density_red_white_density,labels = "AUTO", ncol = 2)
#
plot_grid(density_red_white_chlorides,density_red_white_free_sulfur_dioxide, density_red_white_total_sulfur_dioxide,
density_red_white_sulphates,labels = "AUTO", ncol = 2)
#Creating box plot comparing both red and wine
#
#The boc plot contain the Mann-Whitney p-value. I have not added "alternative = "two.sided"" as is not recognised in the graph.
#However the results are the same as in the full test
#fixed acidity
red_white_fixed_acidity <- ggplot(winequality_dry_5, aes(x=type, y=fixed_acidity, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Fixed Acidity (g/l)", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#citric acid
red_white_citric_acid <- ggplot(winequality_dry_5, aes(x=type, y=citric_acid, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Citric Acid (g/l)", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#volatile acidity
red_white_volatile_acidity <- ggplot(winequality_dry_5, aes(x=type, y=volatile_acidity, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Volatile Acidity (g/l)", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#total acidity
red_white_total_acidity <- ggplot(winequality_dry_5, aes(x=type, y=total_acitity, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Total Acitidy (g/l)", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#ph
red_white_ph <- ggplot(winequality_dry_5, aes(x=type, y=ph, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "PH", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#residual sugar
red_white_residual_sugar <- ggplot(winequality_dry_5, aes(x=type, y=residual_sugar, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Residual Sugar (g/l)", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#alcohol
red_white_alcohol <- ggplot(winequality_dry_5, aes(x=type, y=alcohol, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Alcohol (%)", color = "Type") +
scale_color_manual(values=c("#990000","#CCCC00"))+
stat_compare_means(method = "wilcox.test", paired = FALSE)
#
#density
red_white_density <- ggplot(winequality_dry_5, aes(x=type, y=density, color = type)) +
geom_jitter(alpha = 0.5) +
stat_boxplot(fill = NA,color = "Black") +
labs (x = element_blank(), y = "Density (g/ml)", color = "Type") +