Getting Started with rMosaic

Introduction

rMosaic provides R bindings for Mosaic 0.21.1, a framework for declarative, interactive, and scalable visualizations. This vignette demonstrates basic usage with a working example.

Installation

install.packages("rMosaic")

Example: Voronoi Diagram with YAML

This example demonstrates a Voronoi diagram with interactive controls using YAML format. The visualization includes: - Voronoi cells colored by species - Convex hulls around each species group - Delaunay mesh connecting points - Interactive menus to toggle hull and mesh visibility

library(rMosaic)

# Generate synthetic penguins dataset
set.seed(42)
penguins_df <- data.frame(
  bill_length = rnorm(150, mean = 40, sd = 5),
  bill_depth  = rnorm(150, mean = 18, sd = 3),
  species     = sample(c("Adelie", "Gentoo", "Chinstrap"), 150, replace = TRUE)
)

# Define YAML spec as R list
voronoi_yaml <- list(
  params = list(
    mesh = 0,
    hull = 0
  ),
  vconcat = list(
    # Main plot
    list(
      plot = list(
        list(
          mark = "voronoi",
          data = list(from = "penguins"),
          x = "bill_length",
          y = "bill_depth",
          stroke = "white",
          strokeWidth = 1,
          strokeOpacity = 0.5,
          fill = "species",
          fillOpacity = 0.2
        ),
        list(
          mark = "hull",
          data = list(from = "penguins"),
          x = "bill_length",
          y = "bill_depth",
          stroke = "species",
          strokeOpacity = "$hull",
          strokeWidth = 1.5
        ),
        list(
          mark = "delaunayMesh",
          data = list(from = "penguins"),
          x = "bill_length",
          y = "bill_depth",
          z = "species",
          stroke = "species",
          strokeOpacity = "$mesh",
          strokeWidth = 1
        ),
        list(
          mark = "dot",
          data = list(from = "penguins"),
          x = "bill_length",
          y = "bill_depth",
          fill = "species",
          r = 2
        ),
        list(mark = "frame")
      ),
      width  = 680,
      height = 480
    ),
    # Interactive controls
    list(
      hconcat = list(
        list(
          input   = "menu",
          label   = "Delaunay Mesh",
          options = list(
            list(value = 0,   label = "Hide"),
            list(value = 0.5, label = "Show")
          ),
          as = "$mesh"
        ),
        list(hspace = 5),
        list(
          input   = "menu",
          label   = "Convex Hull",
          options = list(
            list(value = 0, label = "Hide"),
            list(value = 1, label = "Show")
          ),
          as = "$hull"
        )
      )
    )
  )
)

# Run the application
runMosaicApp(
  spec     = voronoi_yaml,
  specType = "yaml",
  data     = list(penguins = penguins_df),
  title    = "Voronoi Diagram (YAML)"
)

Key Features

Next Steps

Explore other vignettes: - format-json.Rmd: Same visualization using JSON format - format-esm.Rmd: Same visualization using ESM (JavaScript) format - taxi-crossfilter.Rmd: Multi-view crossfilter example - athletes-dashboard.Rmd: Complex dashboard with tables and selections - gaia-stars.Rmd: Large-scale astronomical data visualization - dynamic-rendering.Rmd: Dynamic pan/zoom with on-the-fly binning

Check the Mosaic documentation for all available marks and interactions.