| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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
- data Chart
- chart :: DataFrame -> Chart
- data Mark
- data Channel
- data FieldType
- data Agg
- mark :: Mark -> Chart -> Chart
- enc :: Columnable a => Channel -> Expr a -> Chart -> Chart
- encAs :: Columnable a => Channel -> Expr a -> FieldType -> Chart -> Chart
- aggregateOn :: Channel -> Agg -> Chart -> Chart
- binX :: Chart -> Chart
- binY :: Chart -> Chart
- facet :: Columnable a => Expr a -> Chart -> Chart
- row :: Columnable a => Expr a -> Chart -> Chart
- column :: Columnable a => Expr a -> Chart -> Chart
- layer :: [Chart] -> Chart
- regression :: (Columnable a, Columnable b) => Expr a -> Expr b -> Chart -> Chart
- density :: Columnable a => Expr a -> Chart -> Chart
- logScale :: Channel -> Chart -> Chart
- includeZero :: Channel -> Bool -> Chart -> Chart
- title :: Text -> Chart -> Chart
- size :: Int -> Int -> Chart -> Chart
- toVegaSpec :: Chart -> Value
- toHtml :: Chart -> String
- showChart :: Chart -> IO ()
- scatter :: (Columnable a, Columnable b) => Expr a -> Expr b -> DataFrame -> IO ()
- bar :: Columnable a => Expr a -> DataFrame -> IO ()
- histogram :: Columnable a => Expr a -> DataFrame -> IO ()
- line :: (Columnable a, Columnable b) => Expr a -> Expr b -> DataFrame -> IO ()
- pie :: Columnable a => Expr a -> DataFrame -> IO ()
- box :: Columnable a => Expr a -> DataFrame -> IO ()
Chart
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
Instances
Constructors
| Quantitative | |
| Nominal | |
| Ordinal | |
| Temporal |
Aggregation strategy for grouped/categorical plots.
Building blocks
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.
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.
facet :: Columnable a => Expr a -> Chart -> Chart Source #
Facet into small multiples by a column (alias for column).
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).
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).
Rendering
toVegaSpec :: Chart -> Value Source #
The Vega-Lite spec as an aeson Value (escape hatch for advanced use / hvega).
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).
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).