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

DataFrame.Display.Web.Chart.Typed

Description

The schema-checked, typed-expression analogue of DataFrame.Display.Web.Chart. Charts are built over a TypedDataFrame using typed expressions (TExpr, #col), so column references are checked against the schema at compile time and the field type follows from the column's Haskell type.

{-# LANGUAGE OverloadedLabels #-}
import qualified DataFrame.Display.Web.Chart.Typed as Plt

-- one-liner
Plt.scatter #age #fare tdf

-- composable grammar
Plt.showChart
  ( Plt.chart tdf
      |> Plt.mark Plt.Boxplot
      |> Plt.enc Plt.X #region
      |> Plt.enc Plt.Y #value
      |> Plt.enc Plt.Color #grp
      |> Plt.facet #grp
  )

Every combinator delegates to DataFrame.Display.Web.Chart by unwrapping the typed expression (unTExpr) and frame (unTDF); the cols phantom is erased at the boundary.

Synopsis

Chart

data Chart (cols :: [(Symbol, Type)]) Source #

A typed chart: a phantom-cols wrapper over the untyped builder.

chart :: forall (cols :: [(Symbol, Type)]). TypedDataFrame cols -> Chart cols Source #

Start a typed chart from a typed frame.

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 :: forall (cols :: [(Symbol, Type)]). Mark -> Chart cols -> Chart cols Source #

Set the mark type.

enc :: forall a (cols :: [(Symbol, Type)]). Columnable a => Channel -> TExpr cols a -> Chart cols -> Chart cols Source #

Encode a typed expression on a channel (field type inferred from its type).

encAs :: forall a (cols :: [(Symbol, Type)]). Columnable a => Channel -> TExpr cols a -> FieldType -> Chart cols -> Chart cols Source #

Like enc but force the Vega-Lite field type.

aggregateOn :: forall (cols :: [(Symbol, Type)]). Channel -> Agg -> Chart cols -> Chart cols Source #

Apply a declarative aggregation to a channel.

binX :: forall (cols :: [(Symbol, Type)]). Chart cols -> Chart cols Source #

Bin the X (resp. Y) channel.

binY :: forall (cols :: [(Symbol, Type)]). Chart cols -> Chart cols Source #

Bin the X (resp. Y) channel.

facet :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> Chart cols -> Chart cols Source #

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

row :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> Chart cols -> Chart cols Source #

Facet across columns / down rows.

column :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> Chart cols -> Chart cols Source #

Facet across columns / down rows.

layer :: forall (cols :: [(Symbol, Type)]). [Chart cols] -> Chart cols Source #

Overlay several charts sharing data into a single layered chart.

regression :: forall a b (cols :: [(Symbol, Type)]). (Columnable a, Columnable b) => TExpr cols a -> TExpr cols b -> Chart cols -> Chart cols Source #

Add a least-squares regression line fitting y on x.

density :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> Chart cols -> Chart cols Source #

Kernel-density estimate of an expression, drawn as an area.

logScale :: forall (cols :: [(Symbol, Type)]). Channel -> Chart cols -> Chart cols Source #

Put a channel on a log scale.

includeZero :: forall (cols :: [(Symbol, Type)]). Channel -> Bool -> Chart cols -> Chart cols Source #

Anchor (True) or release (False) a channel's scale at zero.

title :: forall (cols :: [(Symbol, Type)]). Text -> Chart cols -> Chart cols Source #

Set the chart title.

size :: forall (cols :: [(Symbol, Type)]). Int -> Int -> Chart cols -> Chart cols Source #

Set the chart size in pixels.

Rendering

toVegaSpec :: forall (cols :: [(Symbol, Type)]). Chart cols -> Value Source #

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

toHtml :: forall (cols :: [(Symbol, Type)]). Chart cols -> String Source #

A self-contained HTML snippet embedding the chart.

showChart :: forall (cols :: [(Symbol, Type)]). Chart cols -> IO () Source #

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

One-shot convenience plots

scatter :: forall a b (cols :: [(Symbol, Type)]). (Columnable a, Columnable b) => TExpr cols a -> TExpr cols b -> TypedDataFrame cols -> IO () Source #

Scatter plot of two typed expressions.

bar :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> TypedDataFrame cols -> IO () Source #

Count of rows per category, as bars.

histogram :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> TypedDataFrame cols -> IO () Source #

Histogram of a numeric expression.

line :: forall a b (cols :: [(Symbol, Type)]). (Columnable a, Columnable b) => TExpr cols a -> TExpr cols b -> TypedDataFrame cols -> IO () Source #

Line chart of y over x.

pie :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> TypedDataFrame cols -> IO () Source #

Pie chart counting rows per category.

box :: forall a (cols :: [(Symbol, Type)]). Columnable a => TExpr cols a -> TypedDataFrame cols -> IO () Source #

Box-and-whisker plot of a numeric expression.