Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating box plot with apexcharter #52

Open
NetZissou opened this issue Jun 18, 2021 · 2 comments
Open

Creating box plot with apexcharter #52

NetZissou opened this issue Jun 18, 2021 · 2 comments

Comments

@NetZissou
Copy link

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!

@pvictor
Copy link
Member

pvictor commented Jun 21, 2021

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]
            )
          )
        }
      )
    )
  )

image

You can also display outliers but doesn't seems to work well with category axis.

Victor

@NetZissou
Copy link
Author

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants