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
p <- plot_ly(diamonds, y = ~price, color = I("black"), 
              alpha = 0.1, boxpoints = "suspectedoutliers")
p1 <- p %>% add_boxplot(x = ~cut)
subplot(
  p1, shareY = TRUE
) %>% hide_legend()
library(plotly)

plot_ly(diamonds, x = ~price, y = ~interaction(clarity, cut)) %>%
  add_boxplot(marker = list(color = "orange", size = 4)) %>%
  layout(yaxis = list(title = "Interaction of Clarity and Cut", tickangle = 45), 
         xaxis = list(title = "Price"))
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## āœ” dplyr     1.1.4     āœ” readr     2.1.5
## āœ” forcats   1.0.0     āœ” stringr   1.5.1
## āœ” lubridate 1.9.3     āœ” tibble    3.2.1
## āœ” purrr     1.0.2     āœ” tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## āœ– dplyr::filter() masks plotly::filter(), stats::filter()
## āœ– dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)


d <- diamonds %>%
  mutate(cc = interaction(clarity, cut))


lvls <- d %>%
  group_by(cc) %>%
  summarise(m = median(price)) %>%
  arrange(m) %>%
  pull(cc)

# Graficar con Plotly
plot_ly(d, x = ~price, y = ~factor(cc, lvls)) %>%
  add_boxplot(color = ~clarity) %>%
  layout(yaxis = list(title = ""),
         title = "GrÔfico de cajas de precio vs. interacción de claridad y corte de diamantes",
         xaxis = list(title = "Precio"))