Make Virtual Reality Charts with R.

Installation

# install.packages("devtools")
devtools::install_github("JohnCoene/acharts")

Example

Scatter and bar example, first generate somewhat random data.

library(aframer)
library(acharts)

COL <- round(runif(20, 1, 5))
HEIGHT <- runif(20, 1, 10)

scatter <- data.frame(
  x = runif(20, 1, 5),
  y = runif(20, 5, 10),
  z = runif(20, 1, 20),
  size = runif(20, .1, .4),
  color = COL
)

bar <- data.frame(
  x = runif(20, 1, 5),
  y = HEIGHT - (HEIGHT/2),
  z = runif(20, 1, 20),
  height = HEIGHT,
  color = COL
)

f <- function(){
    runif(20, 1, 10)
}

line <- data.frame(
    src.x = f(),
    src.y = f(),
    src.z = f(),
    tgt.x = f(),
    tgt.y = f(),
    tgt.z = f()
)

labels <- scatter
labels$z <- labels$z + 1 # off by a meter
labels$text <- glue::glue("height: {round(labels$y)}m")

Then plot.

aCharts$
    new()$
    insert(
        a_entity(
            position = "-10 4 20", rotation = "0 -45 0",
            a_camera()
        )
    )$
    scatter( 
        data = scatter, 
        x = x, 
        y = y, 
        z = z,
        size = size,
        color = color
    )$
    bar(
        data = bar,
        x = x,
        y = y,
        z = z,
        height = height,
        color = color
    )$
    line(
      line, 
      src.x, 
      src.y, 
      src.z, 
      tgt.x,
      tgt.y,
      tgt.z
    )$
    labels(
      data = labels,
      x = x,
      y = y,
      z = z,
      text = text
    )$
    plot()$
    embed()