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   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── 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(dplyr)
library(ggplot2)

1. Create a histogram for sepal length using the iris dataset

ggplot(iris, aes(x = Sepal.Length))+
  geom_histogram(binwidth = 0.3, fill = "blue", color= "black") +
  ggtitle("Histogram of Sepal Lenght")

2. Create a histogram for petal lenght and overlay a density plot

ggplot(iris, aes(x = Petal.Length)) + 
  geom_histogram(aes(y = ..density..), binwidth = 0.2, fill = "lightblue", color = "black") +
  geom_density(color = "darkorange", size = 1) +  # Fun color for density plot
  geom_vline(aes(xintercept = median(Petal.Length)), color = "purple", linetype = "dashed", size = 1) +  # Median line
  geom_vline(aes(xintercept = mean(Petal.Length)), color = "green", linetype = "solid", size = 1) +  # Mean line
  ggtitle("Histogram and Density Plot of Petal Length with Mean and Median")
## 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.

3. Vertically display the distribution of sepal width species using boxplots.

ggplot(iris, aes(x = Species, y = Sepal.Width, fill = Species)) +
  geom_boxplot() +
  coord_flip() +  # Display vertically
  theme(legend.position = "none") +  # Remove legend
  ggtitle("Boxplot of Sepal Width by Species")