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
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Data set used for visualization - ‘mtcars’ Visualization used - ‘Scatterplots’

1st Visualisation - miles per gallon (MPG) and Horsepower (HP)

# Load dataset
data(mtcars)

# Create ggplot2 scatter plot
p <- ggplot(mtcars, aes(x = hp, y = mpg)) +
  geom_point(size = 3, color = "#37409e", shape = 17) +
  labs(
    title = "Miles Per Gallon vs Horsepower",
    subtitle = "Triangles represent data points",
    x = "Horsepower (HP)",
    y = "Miles Per Gallon (MPG)",
    caption = "Source: mtcars dataset"
  ) +
  theme_minimal()

p

# Convert ggplot to plotly
p_interactive <- ggplotly(p)

p_interactive

2nd Visualisation - Horsepower (HP) and miles per gallon (MPG)

# Load dataset
data(mtcars)

# Create ggplot2 scatter plot
p <- ggplot(mtcars, aes(x = mpg , y = hp)) +
  geom_point(size = 2, color = "#b5bbfa", shape = 16) +
  labs(
    title = "Horsepower vs Miles Per Gallon",
    subtitle = "Circles represent data points",
    x = "Miles Per Gallon (MPG)",
    y = "Horsepower (HP)",
    caption = "Source: dataset from mtcars"
  ) +
  theme_minimal()

p

# Convert ggplot to plotly
p_interactive <- ggplotly(p)

p_interactive