library(plotly)
p1 <- plot_ly(diamonds, x = ~price) %>% add_histogram(name = "plotly")
h <- hist(diamonds$price, breaks = "FD", plot = FALSE)
p2 <- plot_ly(x = h$mids, y = h$counts) %>% add_bars(name = "R hist()")
subplot(p1, p2, nrows = 2, shareX = TRUE)