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, eg:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.