5

When I try to set a customized width for my boxplot in ggplot, it works fine:

p=ggplot(iris, aes(x = Species,y=Sepal.Length )) + geom_boxplot(width=0.1)

But when I try to use ggplotly, the width (and the hjust) is default:

p %>% ggplotly()

What am I doing wrong or is this a bug in ggplotly?

Joelle
  • 63
  • 5

1 Answers1

5

You can use layout to set the boxgap:

library(ggplot2)
library(plotly)

p <- ggplot(iris, aes(x = Species,y=Sepal.Length )) +
   geom_boxplot()

ggplotly(p) %>% plotly::layout(boxgap=0.9)

See also https://plot.ly/python/box-plots/#Grouped-Box-Plot

David Jorquera
  • 2,046
  • 12
  • 35
user12728748
  • 8,106
  • 2
  • 9
  • 14