I've been working with R-markdown to generate HTML reports. However, as datasets are huge, building boxplots with the complete data takes too much time, what makes it unfeasible. So I decided pre-calculating summary data and build boxplots from quartiles, mean, median and outlier data using PLOTLY in R. However, I'm struggling when trying to place outliers in the correct x-axis positions for each group of boxplots.
Below, I provide some example code
library(plotly)
library(data.table)
# use summary data for plotly boxplots
# Simulate data.
n <- 10e5
dt <- data.table(trait=rnorm(n),
year=sample(2016:2019, n, replace=TRUE),
line=factor(sample(letters[1:3], n, replace=TRUE)))
# calculate summary data (summary + outliers) separately
stats <- dt[, boxplot.stats(trait)[1], by=.(year, line)]
out <- dt[, boxplot.stats(trait)[4], keyby=.(year, line)]
# create and plot the BOXPLOT
plot_ly() %>%
add_trace(data=stats, x=~year, y=~stats, color=~line, type="box") %>%
layout(boxmode="group") %>%
add_markers(data=out, x=~year, y=~out, color=~line) %>%
config(displayModeBar=FALSE, showTips=FALSE)
The result is a boxplot by groups with outliers being placed on the same x-axis position for each year, but not sub-dividing for each line-group.
Does anyone have any idea how to make add_markers() place those pre-calculated outlier points in the correct positions in the boxplot???