library needed

library(plotly)
## Loading required package: ggplot2
## 
## 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)

get data

data("mtcars")

make the plot

p <- plot_ly(mtcars, x = ~ as.factor(mtcars$cyl),y = mtcars$mpg,color = as.factor(mtcars$cyl) , type = "box") %>%
  layout(
    title = "mpg depending on cyl",
    scene = list(
      xaxis = list(title = "cyl"),
      yaxis = list(title = "mpg")
    ))

p