Formaldehyde
data(Formaldehyde)
plot(Formaldehyde,
main = "Relation between Concentration and Rate of Reaction",
xlab = "Carbohydrate (carb)",
ylab = "Optical Density (optden)",
col = "blue",
pch = 16)
model_f <- lm(optden ~ carb, data = Formaldehyde)
abline(model_f, col = "red", lwd = 2)

data(CO2)
plot(CO2$conc, CO2$uptake,
main = "CO2 Uptake vs Concentration",
xlab = "Concentration",
ylab = "Uptake",
col = "blue",
pch = 16)
model_co2 <- lm(uptake ~ conc, data = CO2)
abline(model_co2, col = "red", lwd = 2)

library(ggplot2)
ggplot(CO2, aes(x = conc, y = uptake)) +
geom_point(color = "blue") +
geom_smooth(method = "lm", color = "red", se = FALSE) +
labs(title = "CO2 Uptake vs Concentration (GGPlot)")
## `geom_smooth()` using formula = 'y ~ x'

data(HairEyeColor)
hair_counts <- margin.table(HairEyeColor, 1)
barplot(hair_counts,
main = "Distribution of Hair Color",
xlab = "Hair Color",
ylab = "Count",
col = rainbow(length(hair_counts)))

hec_df <- as.data.frame(HairEyeColor)
ggplot(hec_df, aes(x = Hair, y = Freq, fill = Eye)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Hair Color vs Eye Color Distribution")
