apexcharter
apexcharter copied to clipboard
Creating box plot with apexcharter
Hi, is there any way that we could generate a box plot using the apexcharter interface? If not, would you mind providing an example of using R to interact with the raw apexchart API to create a boxplot? Thanks!
Hello,
Currently not supported in apex()
, but you can use the full API like this to produce a boxplot:
library(apexcharter)
data("mpg", package = "ggplot2")
boxed <- boxplot(hwy ~ class, data = mpg)
apexchart() %>%
ax_chart(type = "boxPlot") %>%
ax_xaxis(type = "categories", categories = boxed$names) %>%
ax_series(
list(
name = "boxes",
type = "boxPlot",
data = lapply(
X = seq_along(boxed$names),
FUN = function(i) {
list(
x = boxed$names[i],
y = c(
boxed$stats[1, i],
boxed$stats[2, i],
boxed$stats[3, i],
boxed$stats[4, i],
boxed$stats[5, i]
)
)
}
)
)
)
You can also display outliers but doesn't seems to work well with category axis.
Victor
Thank you, Victor. This is exactly what I am looking for. One question on top of this, could we add a smooth line on top of these boxes? It seems like the functions right now only support charts rendered by apex()
.