Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mistake in documentation of ggplotly box plots #58

Open
meldarionqeusse opened this issue Mar 5, 2021 · 0 comments
Open

Mistake in documentation of ggplotly box plots #58

meldarionqeusse opened this issue Mar 5, 2021 · 0 comments

Comments

@meldarionqeusse
Copy link

In this explanation for how to implement geom_boxplot with plotly (https://plotly.com/ggplot2/box-plots/#outliers) there is a mistake in the function used.

Currently the code example reads like this:

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) + 
  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$data <- lapply(fig$data, FUN = function(x){
  x$marker = list(opacity = 0)
  return(x)
})

fig

it should be

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) + 
  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

Note the difference fig$x$data instead of fig$data otherwise this won't remove the outliers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant