I know how to hide outliers with ggplotly and geom_boxplot, as per Removing outliers from boxplot and plotly :
library(plotly)
set.seed(123)
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
p <- ggplot(df, aes(cut, price, fill = cut)) +
geom_boxplot(outlier.shape = NA, outlier.size = NA, outlier.colour = NA) +
ggtitle("Ignore outliers in ggplot2")
# Need to modify the plotly object and make outlier points have opacity equal to 0
fig <- plotly_build(p)
fig$x$data <- lapply(fig$x$data, FUN = function(x){
x$marker = list(opacity = 0)
return(x)
})
fig
But while the visual outlier points are gone, the tooltips remain when you hover over where the points would be, e.g.:

Is there any way to get rid of those specifically while keeping the other tooltips?
This worked for me:
library(plotly)
set.seed(123)
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
p <- ggplot(df, aes(cut, price, fill = cut)) +
geom_boxplot(outlier.shape = NA, outlier.size = NA, outlier.colour = NA) +
ggtitle("Ignore outliers in ggplot2")
# Need to modify the plotly object and make outlier points have opacity equal to 0
fig <- plotly_build(p)
fig$x$data <- lapply(fig$x$data, FUN = function(x){
x$marker = list(opacity = 0)
###### added line to remove hoverinfo:
x$hoverinfo = "none"
###### end of addition
return(x)
})
fig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With