This document is adapted from the Other Charts section of the Altair Example Gallery.

Our first step is to set up our environment:

library("altair")
library("tibble")
library("dplyr")
library("jsonlite")

vega_data <- import_vega_data()

Bar Chart with Highlighted Segment

Altair Example

Chart

Becker’s Barley Trellis Plot (wrapped facet)

Altair Example

Chart

Binned Movie Rating Heatmap

Altair Example

Chart

Box Plot with Min/Max Whiskers

Altair example

This example shows how to make a basic box plot using US Population data from 2000.

Chart

Candlestick Chart

Altair example

A candlestick chart inspired from Protovis. This example shows the performance of the Chicago Board Options Exchange Volatility Index (VIX) in the summer of 2009. The thick bar represents the opening and closing prices, while the thin bar shows intraday high and low prices; if the index closed higher on a given day, the bars are colored green rather than red. #### Data

Definition

data <- 
  jsonlite::fromJSON('[
  {
    "date": "01-Jun-2009",
    "open": 28.7,
    "high": 30.05,
    "low": 28.45,
    "close": 30.04,
    "signal": "short",
    "ret": -4.89396411092985
  },
  {
    "date": "02-Jun-2009",
    "open": 30.04,
    "high": 30.13,
    "low": 28.3,
    "close": 29.63,
    "signal": "short",
    "ret": -0.322580645161295
  },
  {
    "date": "03-Jun-2009",
    "open": 29.62,
    "high": 31.79,
    "low": 29.62,
    "close": 31.02,
    "signal": "short",
    "ret": 3.68663594470045
  },
  {
    "date": "04-Jun-2009",
    "open": 31.02,
    "high": 31.02,
    "low": 29.92,
    "close": 30.18,
    "signal": "short",
    "ret": 4.51010886469673
  },
  {
    "date": "05-Jun-2009",
    "open": 29.39,
    "high": 30.81,
    "low": 28.85,
    "close": 29.62,
    "signal": "short",
    "ret": 6.08424336973478
  },
  {
    "date": "08-Jun-2009",
    "open": 30.84,
    "high": 31.82,
    "low": 26.41,
    "close": 29.77,
    "signal": "short",
    "ret": 1.2539184952978
  },
  {
    "date": "09-Jun-2009",
    "open": 29.77,
    "high": 29.77,
    "low": 27.79,
    "close": 28.27,
    "signal": "short",
    "ret": -5.02431118314424
  },
  {
    "date": "10-Jun-2009",
    "open": 26.9,
    "high": 29.74,
    "low": 26.9,
    "close": 28.46,
    "signal": "short",
    "ret": -5.46623794212217
  },
  {
    "date": "11-Jun-2009",
    "open": 27.36,
    "high": 28.11,
    "low": 26.81,
    "close": 28.11,
    "signal": "short",
    "ret": -8.3743842364532
  },
  {
    "date": "12-Jun-2009",
    "open": 28.08,
    "high": 28.5,
    "low": 27.73,
    "close": 28.15,
    "signal": "short",
    "ret": -5.52763819095477
  },
  {
    "date": "15-Jun-2009",
    "open": 29.7,
    "high": 31.09,
    "low": 29.64,
    "close": 30.81,
    "signal": "long",
    "ret": 3.4920634920635
  },
  {
    "date": "16-Jun-2009",
    "open": 30.81,
    "high": 32.75,
    "low": 30.07,
    "close": 32.68,
    "signal": "short",
    "ret": 0.155038759689914
  },
  {
    "date": "17-Jun-2009",
    "open": 31.19,
    "high": 32.77,
    "low": 30.64,
    "close": 31.54,
    "signal": "short",
    "ret": 5.82822085889571
  },
  {
    "date": "18-Jun-2009",
    "open": 31.54,
    "high": 31.54,
    "low": 29.6,
    "close": 30.03,
    "signal": "short",
    "ret": 8.17610062893082
  },
  {
    "date": "19-Jun-2009",
    "open": 29.16,
    "high": 29.32,
    "low": 27.56,
    "close": 27.99,
    "signal": "short",
    "ret": 8.59872611464968
  },
  {
    "date": "22-Jun-2009",
    "open": 30.4,
    "high": 32.05,
    "low": 30.3,
    "close": 31.17,
    "signal": "short",
    "ret": 15.4907975460123
  },
  {
    "date": "23-Jun-2009",
    "open": 31.3,
    "high": 31.54,
    "low": 27.83,
    "close": 30.58,
    "signal": "short",
    "ret": 11.7370892018779
  },
  {
    "date": "24-Jun-2009",
    "open": 30.58,
    "high": 30.58,
    "low": 28.79,
    "close": 29.05,
    "signal": "long",
    "ret": -10.4234527687296
  },
  {
    "date": "25-Jun-2009",
    "open": 29.45,
    "high": 29.56,
    "low": 26.3,
    "close": 26.36,
    "signal": "long",
    "ret": 0
  },
  {
    "date": "26-Jun-2009",
    "open": 27.09,
    "high": 27.22,
    "low": 25.76,
    "close": 25.93,
    "signal": "long",
    "ret": 0
  },
  {
    "date": "29-Jun-2009",
    "open": 25.93,
    "high": 27.18,
    "low": 25.29,
    "close": 25.35,
    "signal": "long",
    "ret": 5.26315789473684
  },
  {
    "date": "30-Jun-2009",
    "open": 25.36,
    "high": 27.38,
    "low": 25.02,
    "close": 26.35,
    "signal": "long",
    "ret": 6.73758865248228
  }
]')

Chart

Error Bar with Standard Deviation

Altair Example

Chart

Error Bars showing Confidence Interval

Altair Example

This example shows how to show error bars using confidence intervals. The confidence intervals are computed internally in vega by a non-parametric bootstrap of the mean.

Chart

Facetted Scatterplot with marginal histograms

Altair Example

There is a slight difference from the Altair example in the yscale, to get everything to line-up correctly.

Chart

Gantt Chart

Altair example

Chart

Isotype Grid

Altair Example

Data

Definition

data <- tibble(id = 1:100)
person = c("M1.7 -1.7h-0.8c0.3 -0.2 0.6 -0.5 0.6 -0.9c0 -0.6 -0.4 -1 -1 -1c-0.6 0 -1 0.4 -1 1c0 0.4 0.2 0.7 0.6 0.9h-0.8c-0.4 0 -0.7 0.3 -0.7 0.6v1.9c0 0.3 0.3 0.6 0.6 0.6h0.2c0 0 0 0.1 0 0.1v1.9c0 0.3 0.2 0.6 0.3 0.6h1.3c0.2 0 0.3 -0.3 0.3 -0.6v-1.8c0 0 0 -0.1 0 -0.1h0.2c0.3 0 0.6 -0.3 0.6 -0.6v-2c0.2 -0.3 -0.1 -0.6 -0.4 -0.6z")

Chart

Multiple Marks

Altair Example

Chart

Normalized Parallel Coordinates Example

Altair Example

A Parallel Coordinates chart is a chart that lets you visualize the individual data points by drawing a single line for each of them.

Such a chart can be created in Altair by first transforming the data into a suitable representation.

This example shows a modified parallel coordinates chart with the Iris dataset, where the y-axis shows the value after min-max rather than the raw value. It’s a simplified Altair version of the VegaLite version.

Chart

Parallel Coordinates Example

Altair Example

A Parallel Coordinates chart is a chart that lets you visualize the individual data points by drawing a single line for each of them. Such a chart can be created in Altair by first transforming the data into a suitable representation. This example shows a parallel coordinates chart with the Iris dataset.

Chart

Ranged Dot Plot

Altair Example

This example shows a ranged dot plot that uses layer to convey changing life expectancy for the five most populous countries (between 1955 and 2000).

Chart

Ridgeline plot Example

Altair Example

A Ridgeline plot chart is a chart that lets you visualize distribution of a numeric value for several groups.

Such a chart can be created in Altair by first transforming the data into a suitable representation.

Chart

Sorted Error Bars showing Confidence Interval

Altair Example

This example shows how to show error bars using confidence intervals, while also sorting the y-axis based on x-axis values.

Chart

Steam and Leaf Plot

Altair Example

Chart

Text over a Heatmap

Altair Example

An example of a layered chart of text over a heatmap using the cars dataset.

Chart

Violinplot

Altair Example

This example shows how to make a kind of a Violinplot.

Chart