Problem 01

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
library(plotly)
## Warning: package 'plotly' was built under R version 4.4.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
data <- iris
View(data)
str(data)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
g <- ggplot(data, aes(x=Sepal.Length, y=Sepal.Width))
g + geom_point()

g1 <- g + 
  geom_point(color='orange', size=2) +
  geom_smooth(method='lm', col='red', se=FALSE) +
  labs(
    title='Sepal Length vs Sepal Width',
    subtitle='Visualization using iris dataset',
    x='Sepal Length',
    y='Sepal Width',
    caption='Source: iris dataset'
  ) +
  theme_minimal() +
  coord_cartesian(xlim = c(4, 8), ylim = c(2, 4.5))

ggplotly(g1)
## `geom_smooth()` using formula = 'y ~ x'

Problem 02

g2 <- ggplot(data, aes(x=Species, y=Sepal.Length, fill=Species)) +
  geom_boxplot() +
  labs(
    title='Distribution of Sepal Length by Species',
    subtitle='Boxplot showing the distribution of Sepal Length for each species in the Iris dataset',
    x='Species',
    y='Sepal Length',
    caption='Source: iris dataset'
  ) +
  theme_minimal() +
  coord_cartesian(ylim = c(4, 8))


ggplotly(g2)