I have the following code that works fine on my end:
# Seeding the pseudo-random number generator for reproducible results
set.seed(1234)
# Create three varaible
income <- round(rnorm(500, # 500 random data point values
mean = 10000, # mean of 100
sd = 1000), # standard deviation of 1000
digits = 2) # round the random values to two decimal points
stage <- sample(c("Early",
"Mid",
"Late"), # sample space of the stage variable
500, # 500 random data point values
replace = TRUE) # replace values for reselection
country <- sample(c("USA",
"Canada"), # sample space of the country variabe
500, # 500 random data point values
replace = TRUE) # replace values for reselection
# Create tibble
df1 <- tibble(Income = income, # create an Income variable for the income data point values
Stage = stage, # create a Stage variable for the stage data point values
Country = country) # create a Country variable for the country data point values
df1 <- as.data.frame(df1)
df1$HIGHLIGHT <- 'NO'
df1$TMP = paste0(df1$Country,"_",df1$Stage)
idx <- duplicated(df1$TMP)
df1$HIGHLIGHT[!idx] = 'YES'
plot_ly(df1,
x = ~Country,
y = ~Income,
color = ~Stage,
type = "box") %>%
layout(boxmode = "group",
title = "Income by career stage",
xaxis = list(title = "Country",
zeroline = FALSE),
yaxis = list(title = "Income",
zeroline = FALSE))
However, what I would like to add is a red dot over each single boxplot showing the most recent value given by column "HIGHLIGHT" where the value in this column is "YES". This helps uses to see not only the distribution for each boxplot but also where the most recent value is positioned. I can't find a way to add those red dots. Any suggestions? Thank you


add_markersbut no luck. Here is the code I piped onto your plotly code, if you want to try and pick it up from here. The key might be getting the boxplot to group based onStagewithout using theboxmodeargument.add_markers(data = df1 %>% filter(HIGHLIGHT == "YES") %>% group_by(Stage), x = ~Country, y = ~Income)