There are groups of boxplots:
dat <- data.frame(xval = sample(100,1000,replace = TRUE),
group_af = as.factor(sample(c("a","b","c", "e", "f"),1000,replace = TRUE)),
group_xyz = as.factor(sample(c("x","y","z"),1000,replace = TRUE)))
dat <- dat %>%
mutate(aux_var = as.factor(paste0(group_af, "-", group_xyz)))
lvls <- levels(dat$aux_var)
dat %>%
plot_ly() %>%
add_trace(x = ~as.numeric(aux_var),
y = ~xval,
color = ~group_xyz,
type = "box",
hoverinfo = "none",
boxpoints = FALSE) %>%
layout(boxmode = "group") %>%
add_markers(x = ~jitter(as.numeric(aux_var)),
y = ~xval,
color = ~group_xyz,
marker = list(size = 3),
hoverinfo = "text",
text = ~paste0("Group: ", aux_var, "<br>xval: ", xval),
showlegend = TRUE) %>%
layout(
xaxis = list(tickmode = "array",
tickvals = c(1:length(lvls)),
# ticktext = lvls
ticktext = sapply(lvls, function(x) gsub("-.*$", "", x))
))
and I would like to add spaces between groups (or add border to each group) to significantly separate those groups and improve readability:
Is it possible to do this? For example add custom spaces on X axis between specific ticks?