#install.packages("plotly")
#install.packages("ggplot2")
library(plotly)
## Warning: package 'plotly' was built under R version 4.2.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.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(ggplot2)

myPlot <- ggplot(data=mtcars, aes(mpg,hp)) + 
geom_point(aes(colour = factor(cyl))) +
ggtitle("Miles per Gallon (mpg) versus Horsepower (hp)") +
xlab("mpg") +
ylab("hp")

# Make it interactive using ggplotly
ggplotly(myPlot)