dataframe-viz-1.3.1.0: Visualisation/plotting helpers for the dataframe ecosystem.
Safe HaskellNone
LanguageHaskell2010

DataFrame.Display.Web.Chart

Description

A composable, expression-based grammar of graphics over the untyped Expr. Charts are built by piping combinators and rendered to interactive Vega-Lite.

import qualified DataFrame.Display.Web.Chart as Plt
import DataFrame.Functions (col)

Plt.showChart
  ( Plt.chart df
      |> Plt.mark Plt.Point
      |> Plt.enc Plt.X (col @Double "age")
      |> Plt.enc Plt.Y (col @Double "fare")
      |> Plt.enc Plt.Color (col @Text "class")
  )

The element type of each encoded expression determines the Vega-Lite field type (numeric → quantitative, date/time → temporal, otherwise nominal). A bare column expression encodes that column; any other expression is materialised with the core interpreter and inlined under the channel's name.

For the schema-checked typed variant see DataFrame.Display.Web.Chart.Typed.

Synopsis

Chart

data Chart Source #

An in-progress chart: the source frame, a mark, channel encodings, the data fields to inline, transforms, and (for layered charts) sub-layers.

chart :: DataFrame -> Chart Source #

Start a chart from a frame. Defaults to a point mark at 600x400.

Re-exported spec vocabulary

data Mark Source #

Constructors

Bar 
Line 
Point 
Area 
Boxplot 
Arc 
Rule 
Tick 

Instances

Instances details
Show Mark Source # 
Instance details

Defined in DataFrame.Display.Internal.VegaLite

Methods

showsPrec :: Int -> Mark -> ShowS #

show :: Mark -> String #

showList :: [Mark] -> ShowS #

Eq Mark Source # 
Instance details

Defined in DataFrame.Display.Internal.VegaLite

Methods

(==) :: Mark -> Mark -> Bool #

(/=) :: Mark -> Mark -> Bool #

data Channel Source #

Constructors

X 
Y 
Color 
Size 
Shape 
Column 
Row 
Opacity 
Theta 
Tooltip 
Order 

Instances

Instances details
Show Channel Source # 
Instance details

Defined in DataFrame.Display.Internal.VegaLite

Eq Channel Source # 
Instance details

Defined in DataFrame.Display.Internal.VegaLite

Methods

(==) :: Channel -> Channel -> Bool #

(/=) :: Channel -> Channel -> Bool #

data FieldType Source #

Instances

Instances details
Show FieldType Source # 
Instance details

Defined in DataFrame.Display.Internal.VegaLite

Eq FieldType Source # 
Instance details

Defined in DataFrame.Display.Internal.VegaLite

data Agg Source #

Aggregation strategy for grouped/categorical plots.

Constructors

Count

Count rows per group; ignores the value column.

Sum

Sum of value column per group.

Mean

Arithmetic mean of value column per group.

Median

Median of value column per group.

Min

Minimum of value column per group.

Max

Maximum of value column per group.

Instances

Instances details
Show Agg Source # 
Instance details

Defined in DataFrame.Display.Internal.Common

Methods

showsPrec :: Int -> Agg -> ShowS #

show :: Agg -> String #

showList :: [Agg] -> ShowS #

Eq Agg Source # 
Instance details

Defined in DataFrame.Display.Internal.Common

Methods

(==) :: Agg -> Agg -> Bool #

(/=) :: Agg -> Agg -> Bool #

Building blocks

mark :: Mark -> Chart -> Chart Source #

Set the mark type.

enc :: Columnable a => Channel -> Expr a -> Chart -> Chart Source #

Encode an expression on a channel. The field type is inferred from the expression's element type; use encAs to override.

encAs :: Columnable a => Channel -> Expr a -> FieldType -> Chart -> Chart Source #

Like enc but force the Vega-Lite field type (e.g. Temporal, Ordinal).

aggregateOn :: Channel -> Agg -> Chart -> Chart Source #

Apply a declarative aggregation to a channel (computed by Vega-Lite). For Count the field is dropped, matching Vega-Lite's fieldless count.

binX :: Chart -> Chart Source #

Bin the X (resp. Y) channel (Vega-Lite bin transform).

binY :: Chart -> Chart Source #

Bin the X (resp. Y) channel (Vega-Lite bin transform).

facet :: Columnable a => Expr a -> Chart -> Chart Source #

Facet into small multiples by a column (alias for column).

row :: Columnable a => Expr a -> Chart -> Chart Source #

Facet across columns / down rows.

column :: Columnable a => Expr a -> Chart -> Chart Source #

Facet across columns / down rows.

layer :: [Chart] -> Chart Source #

Overlay several charts that share data into a single layered chart. The title and size of the first layer are used for the container.

regression :: (Columnable a, Columnable b) => Expr a -> Expr b -> Chart -> Chart Source #

Add a regression (least-squares) line over the chart, fitting y on x. Produces a layered chart: the original marks plus a fitted line.

density :: Columnable a => Expr a -> Chart -> Chart Source #

Kernel-density estimate of an expression, drawn as an area. Replaces the chart's mark and encodings with the density curve (Vega-Lite density).

logScale :: Channel -> Chart -> Chart Source #

Put a channel on a log scale. Like all channel modifiers, apply it after enc on the same channel (enc replaces the whole encoding).

includeZero :: Channel -> Bool -> Chart -> Chart Source #

Anchor (True) or release (False) a channel's scale at zero. Vega-Lite includes zero on quantitative scales by default, which squashes data far from the origin (e.g. geographic coordinates) against the chart edge; includeZero X False lets the axis fit the data instead. Apply it after enc on the same channel (enc replaces the whole encoding).

title :: Text -> Chart -> Chart Source #

Set the chart title.

size :: Int -> Int -> Chart -> Chart Source #

Set the chart size in pixels.

Rendering

toVegaSpec :: Chart -> Value Source #

The Vega-Lite spec as an aeson Value (escape hatch for advanced use / hvega).

toHtml :: Chart -> String Source #

A self-contained HTML snippet embedding the chart.

showChart :: Chart -> IO () Source #

Render the chart to a temp file and open it in the default browser.

One-shot convenience plots

scatter :: (Columnable a, Columnable b) => Expr a -> Expr b -> DataFrame -> IO () Source #

Scatter plot of two expressions. Axes fit the data (no zero anchor).

bar :: Columnable a => Expr a -> DataFrame -> IO () Source #

Count of rows per category, as bars.

histogram :: Columnable a => Expr a -> DataFrame -> IO () Source #

Histogram of a numeric expression (Vega-Lite binning + count).

line :: (Columnable a, Columnable b) => Expr a -> Expr b -> DataFrame -> IO () Source #

Line chart of y over x. Axes fit the data (no zero anchor).

pie :: Columnable a => Expr a -> DataFrame -> IO () Source #

Pie chart counting rows per category.

box :: Columnable a => Expr a -> DataFrame -> IO () Source #

Box-and-whisker plot of a numeric expression.