ggvis

star 5

R ggvis package for interactive graphics. Use for creating interactive web graphics with a grammar of graphics.

LeoLin990405 By LeoLin990405 schedule Updated 1/30/2026

name: ggvis description: R ggvis package for interactive graphics. Use for creating interactive web graphics with a grammar of graphics.

ggvis

Interactive web graphics with grammar of graphics.

Basic Plots

library(ggvis)

# Scatter plot
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points()

# Line plot
df %>%
  ggvis(~x, ~y) %>%
  layer_lines()

# Bar plot
df %>%
  ggvis(~category) %>%
  layer_bars()

Aesthetics

mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points(
    fill = ~factor(cyl),
    size = ~hp,
    opacity := 0.5
  )

# := for fixed values, ~ for mapped values
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points(
    fill := "red",      # Fixed color
    size := 100,        # Fixed size
    stroke := "black"   # Fixed stroke
  )

Multiple Layers

mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points() %>%
  layer_smooths(stroke := "red")

# Points with lines
df %>%
  ggvis(~x, ~y) %>%
  layer_points() %>%
  layer_lines()

Interactivity

# Tooltips
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points() %>%
  add_tooltip(function(df) df$mpg)

# Custom tooltip
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points() %>%
  add_tooltip(function(df) {
    paste0("MPG: ", df$mpg, "<br>", "Weight: ", df$wt)
  }, "hover")

Input Controls

# Slider
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points(
    size := input_slider(10, 300, value = 50, label = "Size")
  )

# Select
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points(
    fill := input_select(c("red", "blue", "green"), label = "Color")
  )

# Checkbox
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points(
    opacity := input_checkbox(label = "Transparent", map = function(x) if(x) 0.3 else 1)
  )

Scales

mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points(fill = ~factor(cyl)) %>%
  scale_nominal("fill", range = c("red", "blue", "green"))

# Axis customization
mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points() %>%
  add_axis("x", title = "Weight") %>%
  add_axis("y", title = "Miles per Gallon")

Legends

mtcars %>%
  ggvis(~wt, ~mpg, fill = ~factor(cyl)) %>%
  layer_points() %>%
  add_legend("fill", title = "Cylinders")

Histograms and Density

# Histogram
mtcars %>%
  ggvis(~mpg) %>%
  layer_histograms(width = 2)

# Density
mtcars %>%
  ggvis(~mpg) %>%
  layer_densities()

Grouping

mtcars %>%
  ggvis(~wt, ~mpg) %>%
  layer_points() %>%
  layer_smooths() %>%
  group_by(cyl)

Shiny Integration

# In Shiny UI
ggvisOutput("plot")

# In Shiny server
bind_shiny(
  mtcars %>%
    ggvis(~wt, ~mpg) %>%
    layer_points(),
  "plot"
)
Install via CLI
npx skills add https://github.com/LeoLin990405/r-analytics-skill --skill ggvis
Repository Details
star Stars 5
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
LeoLin990405
LeoLin990405 Explore all skills →