Plotly: boxes overlap when using ggplotly and geom_boxplot with a fill variable

Created on 11 Aug 2016  路  6Comments  路  Source: ropensci/plotly

library(plyr)
library(reshape2)
library(plotly)

set.seed(1234)
x<- rnorm(100)
y.1<-rnorm(100)
y.2<-rnorm(100)
y.3<-rnorm(100)
y.4<-rnorm(100)

df<- (as.data.frame(cbind(x,y.1,y.2,y.3,y.4)))

dfmelt<-melt(df, measure.vars = 2:5)

ggplot(dfmelt, aes(x=factor(round_any(x,0.5)), y=value,fill=variable)) + geom_boxplot()

ggplotly()

Most helpful comment

Hi,
this can be solved by addig %>%layout(boxmode = "group"), i.e. use

p <-ggplot(dfmelt, aes(x=factor(round_any(x,0.5)), y=value,fill=variable)) + geom_boxplot()
ggplotly(p)%>%layout(boxmode = "group")

All 6 comments

Hi,
this can be solved by addig %>%layout(boxmode = "group"), i.e. use

p <-ggplot(dfmelt, aes(x=factor(round_any(x,0.5)), y=value,fill=variable)) + geom_boxplot()
ggplotly(p)%>%layout(boxmode = "group")

Thanks @ukkonen !!

Thanks @ukkonen !!

it helped me also

Thanks @ukkonen

Hi,
this can be solved by addig %>%layout(boxmode = "group"), i.e. use

p <-ggplot(dfmelt, aes(x=factor(round_any(x,0.5)), y=value,fill=variable)) + geom_boxplot()
ggplotly(p)%>%layout(boxmode = "group")

Thanks! As a note, while this solution works, it also gives the warning:

Warning message:
'layout' objects don't have these attributes: 'boxmode'
Valid attributes include:
'font', 'title', 'uniformtext', 'autosize', 'width', 'height', 'margin', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'showlegend', 'colorway', 'datarevision', 'uirevision', 'editrevision', 'selectionrevision', 'template', 'modebar', 'meta', 'transition', '_deprecated', 'clickmode', 'dragmode', 'hovermode', 'hoverdistance', 'spikedistance', 'hoverlabel', 'selectdirection', 'grid', 'calendar', 'xaxis', 'yaxis', 'ternary', 'scene', 'geo', 'mapbox', 'polar', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'editType', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'sliders', 'colorscale', 'coloraxis', 'metasrc', 'barmode', 'bargap', 'mapType'

But we can just ignore it apparently (#994).

Was this page helpful?
0 / 5 - 0 ratings