Data Viz - Lab 3.1

library(datasetsICR)
data(wine)

#Convert the 'Class' variable to a factor
wine$Class <- as.factor(wine$Class)

#First 10 rows, last 10 rows, and the structure of the dataset

head(wine, 10)
   Class Alcohol Malic acid  Ash Alcalinity of ash Magnesium Total phenols
1      1   14.23       1.71 2.43              15.6       127          2.80
2      1   13.20       1.78 2.14              11.2       100          2.65
3      1   13.16       2.36 2.67              18.6       101          2.80
4      1   14.37       1.95 2.50              16.8       113          3.85
5      1   13.24       2.59 2.87              21.0       118          2.80
6      1   14.20       1.76 2.45              15.2       112          3.27
7      1   14.39       1.87 2.45              14.6        96          2.50
8      1   14.06       2.15 2.61              17.6       121          2.60
9      1   14.83       1.64 2.17              14.0        97          2.80
10     1   13.86       1.35 2.27              16.0        98          2.98
   Flavanoids Nonflavanoid phenols Proanthocyanins Color intensity  Hue
1        3.06                 0.28            2.29            5.64 1.04
2        2.76                 0.26            1.28            4.38 1.05
3        3.24                 0.30            2.81            5.68 1.03
4        3.49                 0.24            2.18            7.80 0.86
5        2.69                 0.39            1.82            4.32 1.04
6        3.39                 0.34            1.97            6.75 1.05
7        2.52                 0.30            1.98            5.25 1.02
8        2.51                 0.31            1.25            5.05 1.06
9        2.98                 0.29            1.98            5.20 1.08
10       3.15                 0.22            1.85            7.22 1.01
   OD280/OD315 of diluted wines Proline
1                          3.92    1065
2                          3.40    1050
3                          3.17    1185
4                          3.45    1480
5                          2.93     735
6                          2.85    1450
7                          3.58    1290
8                          3.58    1295
9                          2.85    1045
10                         3.55    1045
tail(wine, 10)
    Class Alcohol Malic acid  Ash Alcalinity of ash Magnesium Total phenols
169     3   13.58       2.58 2.69              24.5       105          1.55
170     3   13.40       4.60 2.86              25.0       112          1.98
171     3   12.20       3.03 2.32              19.0        96          1.25
172     3   12.77       2.39 2.28              19.5        86          1.39
173     3   14.16       2.51 2.48              20.0        91          1.68
174     3   13.71       5.65 2.45              20.5        95          1.68
175     3   13.40       3.91 2.48              23.0       102          1.80
176     3   13.27       4.28 2.26              20.0       120          1.59
177     3   13.17       2.59 2.37              20.0       120          1.65
178     3   14.13       4.10 2.74              24.5        96          2.05
    Flavanoids Nonflavanoid phenols Proanthocyanins Color intensity  Hue
169       0.84                 0.39            1.54        8.660000 0.74
170       0.96                 0.27            1.11        8.500000 0.67
171       0.49                 0.40            0.73        5.500000 0.66
172       0.51                 0.48            0.64        9.899999 0.57
173       0.70                 0.44            1.24        9.700000 0.62
174       0.61                 0.52            1.06        7.700000 0.64
175       0.75                 0.43            1.41        7.300000 0.70
176       0.69                 0.43            1.35       10.200000 0.59
177       0.68                 0.53            1.46        9.300000 0.60
178       0.76                 0.56            1.35        9.200000 0.61
    OD280/OD315 of diluted wines Proline
169                         1.80     750
170                         1.92     630
171                         1.83     510
172                         1.63     470
173                         1.71     660
174                         1.74     740
175                         1.56     750
176                         1.56     835
177                         1.62     840
178                         1.60     560
str(wine)
'data.frame':   178 obs. of  14 variables:
 $ Class                       : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
 $ Alcohol                     : num  14.2 13.2 13.2 14.4 13.2 ...
 $ Malic acid                  : num  1.71 1.78 2.36 1.95 2.59 1.76 1.87 2.15 1.64 1.35 ...
 $ Ash                         : num  2.43 2.14 2.67 2.5 2.87 2.45 2.45 2.61 2.17 2.27 ...
 $ Alcalinity of ash           : num  15.6 11.2 18.6 16.8 21 15.2 14.6 17.6 14 16 ...
 $ Magnesium                   : int  127 100 101 113 118 112 96 121 97 98 ...
 $ Total phenols               : num  2.8 2.65 2.8 3.85 2.8 3.27 2.5 2.6 2.8 2.98 ...
 $ Flavanoids                  : num  3.06 2.76 3.24 3.49 2.69 3.39 2.52 2.51 2.98 3.15 ...
 $ Nonflavanoid phenols        : num  0.28 0.26 0.3 0.24 0.39 0.34 0.3 0.31 0.29 0.22 ...
 $ Proanthocyanins             : num  2.29 1.28 2.81 2.18 1.82 1.97 1.98 1.25 1.98 1.85 ...
 $ Color intensity             : num  5.64 4.38 5.68 7.8 4.32 6.75 5.25 5.05 5.2 7.22 ...
 $ Hue                         : num  1.04 1.05 1.03 0.86 1.04 1.05 1.02 1.06 1.08 1.01 ...
 $ OD280/OD315 of diluted wines: num  3.92 3.4 3.17 3.45 2.93 2.85 3.58 3.58 2.85 3.55 ...
 $ Proline                     : int  1065 1050 1185 1480 735 1450 1290 1295 1045 1045 ...
#Summary statistics for 'Alcohol' and 'Color intensity'

summary(wine$Alcohol)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  11.03   12.36   13.05   13.00   13.68   14.83 
summary(wine$`Color intensity`)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.280   3.220   4.690   5.058   6.200  13.000 
#table for the 'Class' categorical variable

table(wine$Class)

 1  2  3 
59 71 48 
#Chart: Relationship between Alcohol and Color Intensity

library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.3.2
ggplot(wine, aes(x = Alcohol, y = `Color intensity`, color = Class)) +
  geom_point() +
  labs(x = "Alcohol", y = "Color Intensity", 
       title = "Relationship between Alcohol and Color Intensity in Wine Varieties",
       subtitle = "Highlighting the Distribution by Wine Class",
       caption = "Data source: datasetsICR package") +
  theme_minimal() +
  scale_color_brewer(type = "qual")

#INSIGHTS

The scatter plot I used provides a visual summary of the relationship between alcohol content and color intensity in wines, broken down by class.

Key takeaways include:

  1. Wine Class 1 tends to have a wider range of alcohol content, roughly between 12.5% to 14.5%, with varying color intensities.

  2. Wine Class 2 generally appears to have a lower alcohol content, mostly concentrated between 12% and 13%, and also exhibits a lower range of color intensity compared to Class 1.

  3. Wine Class 3 shows a more compact grouping in terms of alcohol content, primarily between 13% and 14%, with color intensity spread across a wider range similar to Class 1.

The data suggest some level of relationship between higher alcohol content and color intensity within Class 1, but this trend is not consistent across all classes.

The distribution of points does not strongly support a uniform relationship between alcohol and color intensity across classes, pointing to the complexity of wine characteristics.

#the end