install.packages("plotly")
##
## The downloaded binary packages are in
## /var/folders/67/32gwlz7s3z7dm451ptq50z940000gn/T//RtmpiE4xub/downloaded_packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── 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(dplyr)
# Load required library
library(ggplot2)
# Read the glass.csv file
glass <- read.csv("~/Desktop/glass.csv")
# Scatter plot: Refractive Index vs Sodium
ggplot(glass, aes(x = Na, y = Refractive_Index)) +
geom_point(aes(color = factor(Types_of_Glass)), size = 3) +
labs(title = "Refractive_Index vs Sodium_Content",
x = "Sodium (Na)",
y = "Refractive Index",
color = "Glass Type") +
theme_minimal()
# Box plot: Calcium by Glass Type
ggplot(glass, aes(x = factor(Types_of_Glass), y = Ca)) +
geom_boxplot(aes(fill = factor(Types_of_Glass))) +
labs(title = "Calcium Content by Glass Type",
x = "Glass Type",
y = "Calcium (Ca)",
fill = "Type") +
theme_minimal()
# Box plot: Refractive Index by Glass Type
ggplot(glass, aes(x = factor(Types_of_Glass), y = Refractive_Index)) +
geom_boxplot(aes(fill = factor(Types_of_Glass)), show.legend = FALSE) +
labs(title = "Refractive Index Distribution by Glass Type",
x = "Glass Type",
y = "Refractive Index") +
theme_minimal()
# Histogram: Distribution of Refractive Index
ggplot(glass, aes(x = Refractive_Index)) +
geom_histogram(bins = 20, fill = "steelblue", color = "black") +
labs(title = "Distribution of Refractive Index",
x = "Refractive Index",
y = "Frequency") +
theme_minimal()
# Histogram: Distribution of Sodium
ggplot(glass, aes(x = Na)) +
geom_histogram(bins = 25, fill = "coral", color = "black", alpha = 0.7) +
labs(title = "Distribution of Sodium Content",
x = "Sodium (Na)",
y = "Frequency") +
theme_minimal()
# Histogram with density curve: Calcium distribution
ggplot(glass, aes(x = Ca)) +
geom_histogram(aes(y = ..density..), bins = 20, fill = "lightblue", alpha = 0.7) +
geom_density(color = "darkblue", size = 1.2) +
labs(title = "Distribution of Calcium with Density Curve",
x = "Calcium (Ca)",
y = "Density") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
#### Line graph: Refractive Index across samples (by ID)
# Line graph: Refractive Index across samples (by ID)
ggplot(glass, aes(x = Id, y = Refractive_Index)) +
geom_line(color = "darkgreen", size = 1) +
labs(title = "Refractive Index Across Sample IDs",
x = "Sample ID",
y = "Refractive Index") +
theme_minimal()
#### Line graph: Multiple elements over sample IDs
# Line graph: Multiple elements over sample IDs
ggplot(glass, aes(x = Id)) +
geom_line(aes(y = Na, color = "Sodium"), size = 1) +
geom_line(aes(y = Mg, color = "Magnesium"), size = 1) +
geom_line(aes(y = Al, color = "Aluminum"), size = 1) +
labs(title = "Chemical Elements Across Samples",
x = "Sample ID",
y = "Concentration",
color = "Element") +
theme_minimal()
#### Line graph: Silicon content by Glass Type
# Line graph by Glass Type
ggplot(glass, aes(x = Id, y = Si, color = factor(Types_of_Glass))) +
geom_line(size = 1) +
labs(title = "Silicon Content by Glass Type",
x = "Sample ID",
y = "Silicon (Si)",
color = "Glass Type") +
theme_minimal()
The box plots, of Calcium Content and Refractive Index, display the distribution of chemical properties of elements across glass types. Several glass types show right-skewed (positively skewed) distributions with medians closer to the lower quartile and longer whiskers extending upward, indicating occasional samples with unusually high Refractive index and calcium content.
This histogram showing the distribution of refractive index is slightly right-skewed (positively skewed) with a peak around 1.518 and a tail extending toward higher refractive index values. The majority of glass samples cluster in the lower range, with fewer samples having higher refractive indices, creating an asymmetric distribution
The histogram showing the distribution of sodium content is right-skewed (positively skewed), with a peak around 13-14 units and a long tail extending toward higher sodium values. While the graph is right skewed, a long tail extends towards lower sodium concentrations. Most glass samples have relatively high sodium content, with fewer samples containing lower amounts.
The distribution of calcium content This distribution appears approximately normal or slightly right-skewed, with a smooth bell-shaped density curve. The peak occurs around the middle values with relatively symmetric tails on both sides, though there may be a slight elongation toward higher values.