Install and load the library

install.packages("plotly")
library(plotly)

plot_ly plots with mtcars data

library(plotly)
## Warning: package 'plotly' was built under R version 3.4.2
## Warning: package 'ggplot2' was built under R version 3.4.1
plot_ly(mtcars, x = ~wt, y = ~mpg, type = "scatter", color = ~factor(cyl))

Thanks!