Black Lives Matter. Please consider donating to Black Girls Code today.

Ggplotly ignoring geom_boxplot outlier parameters

Hi,
I want to hide the outliers in the basic geom_boxplot so that I don’t get duplicate points when I overlay it with a geom_jitter. This is so I can hover over the jitter points and get the point details. I am able to get the plot to render ok with basic ggplot; but it looks like ggplotly ignores the outlier parameter settings resulting in duplicate points. Has anyone else seen this? Any suggestions?

My R version is 3.3.1 (2016-06-21), and the version of plotly is ‘3.6.0’,

Example code with mtcars data set:


library(ggplot2)
library(plotly)
carsbp<-ggplot(mtcars,aes(as.factor(cyl),mpg,col=as.factor(cyl)))+geom_boxplot(outlier.colour=NA)+geom_jitter(aes(text=paste(rownames(mtcars))))+xlab(“cyl”)

#check for no duplicate outliers in ggplot
carsbp

#view with ggplotly, see duplicate at cyl = 8, at 10.4 mpg
ggplotly(carsbp)


Thanks,
Melissa

Colin from my team guided me here:

We had to modify the example code to not hide all points including jitter layer:
plotbp<-plotly_build(carsbp)
plotbp$data[1:length(plotbp$data)/2]<-lapply(plotbp$data[1:length(plotbp$data)/2],FUN=function(x){x$marker=list(opacity=0); return(x)})
plotbp

The length of $data will probably vary on number of layers in your ggplot object. Mine had 2 layers (boxplot and jitter) so I divided by 2.