Phil.He
Phil.He

Reputation: 154

Assign ID to outliers in plotly boxplot

I am working with a plotly boxplot (show in the picture below) that presents outliers.

I was wondering whether there was a way to add the ID (that is stored in the same dataframe to create this boxplot) to each outlier?

I was trying to find information on this on Stackoverflow etc, but could not find anything for plotly only for ggplot2.

A reproducible example of my df and code:

df <- data.frame(ID=c("806", "KC68", "364k"), value=c(100, 202, 308))
library(plotly)
plot_ly(y=df$value, type = "box")

Thank you so much in advanceBoxplot

Upvotes: 0

Views: 377

Answers (1)

dww
dww

Reputation: 31452

Something like this (note I changed the values in df to make sure there are outliers in the data):

df <- data.frame(
  ID=c("806", "KC68", "364k", paste0("r", 1:10)), 
  value=c(100, 202, 308, rnorm(10,10,10)))

plot_ly(df, y=~value) %>%
  add_boxplot(hovertext = paste("ID :", df$ID))

Upvotes: 2

Related Questions