Skip to content

Geometries

Each geometry below acts as a single layer within a GG visualization. The layers can be composed using .qp.stack or .qp.split to create custom visualizations.

The geomtries that are available are provided in the grid below, with further detail and examples of each following.

Examples

Each of the examples below can be rendered in the IDE by prepending .qp.go[width; height] to the front of the plot description, or can be rendered to a PNG file using .qp.png[`:filename.png; width; height] in front. For example, use the following for a 500 pixel by 500 pixel scatter chart:

t: ([]x: til 45);

.qp.go[500; 500] .qp.point[t; `x; `y; ::]

.qp.area

Area chart - draw a filled line given the X and Y coordinates of the line.

  • X - horizontal position
  • Y - vertical position

Series can be stacked (see examples below).

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `stack
  • `decorations - Disable line and point decorations

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification table for a line chart

Example: Load data and basic plot

      t : ([]x: til 100; y: { sin[3*x] + sin[2*x] } acos[-1] * til[100] % 100);

      .qp.area[t; `x; `y; ::]

Image

Example: Disable points and outline


      .qp.area[t; `x; `y]
          .qp.s.geom[enlist[`decorations]!enlist 0b]

Image

Example: Filled and alpha

      .qp.area[t; `x; `y]
          .qp.s.geom[`alpha`areaAlpha`fill!(0x7f; 0x2f; 0xb22222)]

Image

Example: Grouped and stacked

      t : raze { ([]
             x: til 100; 
             y: 5 + { sin[rand[5]*x] + sin[rand[5]*x] } acos[-1] * til[100] % 100; z: x) 
         } each `a`b`c;

      .qp.area[t; `x; `y]
            .qp.s.aes[`fill`group; `z`z]
          , .qp.s.scale[`fill; .gg.scale.colour.cat10]
          , .qp.s.geom[``position!(::; `stack)]

Image

Example: Grouped and stacked with properties

      .qp.area[t; `x; `y]
            .qp.s.aes[`fill`group; `z`z]
          , .qp.s.scale[`fill; .gg.scale.colour.cat `blues]
          , .qp.s.geom[`colour`position`alpha`strokewidth!(`black; `stack; 0x7f; 3)] 

Image

.qp.bar

Vertical bar chart.

  • X - places the bar along the x axis
  • Y - maps the height of the bar

Series can be stacked or dodged (see examples below).

By default, the bars will start at the smallest value, unless extended in order to get a nice range for axis ticks. The minimum or maximum can be extended to any desired value. This is useful to set the minimum to 0 to compare the absolute heights rather than the relative heights. This is done by setting the .gg.scale.limits[(min;max)] on the Y scale.

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `dodge or `stack
  • `gap - Gap between bars as percent of width/height (i.e., 0.03 for 3%)
  • `align - Bar alignment
  • `sortByValue - Sort bars by y axis value (largest to smallest)

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a bar chart

See Also: .gg.scale.limits

Example: Load data and basic plot

     t: ([] x: 15#.Q.a; y: 10 + sums 15?-2 -1 1 2);

     .qp.bar[t; `x; `y; ::]

Image

Example: Change colour and order by value

      .qp.bar[t; `x; `y]
          .qp.s.geom[``fill`sortByValue!(::; 0x0070cd; 1b)]

Image

Example: Annotate with text labels and start at 0

     .qp.stack (
         .qp.bar[t; `x; `y]
              .qp.s.geom[``fill`sortByValue!(::; 0x0070cd; 0b)];
         .qp.text[t; `x; `y; `y]
              .qp.s.geom[``offsety`align`bold`size!(::;-10;`middle;1b;11)])

Image

Example: Grouped

      t: raze { ([] cat:x; x: 15#.Q.a; y: 10 + sums 15?-2 -1 1 2)} each `cat1`cat2`cat3`cat4;

      .qp.bar[t; `x; `y]
            .qp.s.aes[`fill; `cat]

Image

Example: Grouped and stacked

      .qp.bar[t; `x; `y]
            .qp.s.aes[`fill`group; `cat`cat]
          , .qp.s.geom[``position!(::; `stack)]
          , .qp.s.scale[`fill; .gg.scale.colour.cat `reds]

Example: Grouped and dodged with custom y and fill scales


      .qp.bar[select from t where x in "abcde"; `x; `y]
            .qp.s.aes   [`fill`group; `cat`cat]
          , .qp.s.geom  [``position`gap!(::; `dodge;0.05)]
          , .qp.s.scale [`fill; .gg.scale.colour.cat `rdbu]
             // start y axis at 0
          , .qp.s.scale [`y; .gg.scale.limits[0 0N] .gg.scale.linear]

Image

Example: Draw a ribbon through the median and deviation of each category

      .qp.stack (
         .qp.bar[select from t where x in "abcde"; `x; `y]
                .qp.s.aes   [`fill`group; `cat`cat]
              , .qp.s.geom  [``position`gap!(::; `dodge;0.05)]
              , .qp.s.scale [`fill; .gg.scale.colour.cat `rdbu]
                 // start y axis at 0
              , .qp.s.scale [`y; .gg.scale.limits[0 0N] .gg.scale.linear];
         .qp.ribbon[select med y, dev y by x from t where x in "abcde"; `x; `y; `y1]
             .qp.s.geom[``alpha!(::;0x3f)])

Image

.qp.boxplot

Box plot showing median, first and third quartiles, farthest point within 1.5 times the interquartile range from the median on either side, and all outliers (points further than this).

  • X - Category (position along the horizontal)
  • Y - Continuous value (value to summarize)

The X column should be a category, and the Y column continuous.

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a box plot

Example: Load data and basic categorical plot

      t : ([]x: raze 50#enlist 10?`5; y: 500?50; z: raze 50#'til 10);

      .qp.boxplot[t; `x; `y; ::]

Image

Example: Basic numeric plot

      .qp.boxplot[t; `z; `y; ::]

Image

.qp.empty

Return an empty plot. Can be used as a spacer.

Returns:

Type Description
table specification tree for an empty plot (spacer)

Example: Empty plot

      .qp.empty[]

.qp.errorbar

Vertical error bar geometry.

  • X - position along the horizontal
  • Y - first point of the interval
  • YEND - second point of the interval

Series can be dodged (see examples below).

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `position - `dodge

Parameters:

Name Type Description
table table
x symbol column name
y symbol column name
yend symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table tree specifying an interval chart

Example: Stacking with a point

      t:update l1:x-.25,l2:x+.25 from 
          0!select max x by y, y2 from 
          ([]x:.st.gen.normal 100;y:100?`a`b`c`d; y2:100?`e`f`g`h);

      .qp.stack (
         .qp.errorbar[select from t where y2=`e; `y; `l1; `l2; ::];
         .qp.point   [select from t where y2=`e; `y; `x]
             .qp.s.geom[``size!(::;5)])

Image

Example: Dodged error bars stacked with bars

     .qp.stack (
         .qp.bar[t;`y;`x] 
             .qp.s.aes[`group`fill; `y2`y2] , 
             .qp.s.scale[`fill; .gg.scale.colour.cat `rdylbu] ,
             .qp.s.geom[``position!(::;`dodge)];
         .qp.errorbar[t;`y;`l1;`l2] 
             .qp.s.aes[`group; `y2] , 
             .qp.s.geom[``position`fill!(::;`dodge;`black)])

Image

.qp.hbar

Horizontal bar chart.

  • X - length of the bar
  • Y - vertical position

Series can be stacked or dodged (see examples below).

By default, the bars will start at the smallest value, unless extended in order to get a nice range for axis ticks. The minimum or maximum can be extended to any desired value. This is useful to set the minimum to 0 to compare the absolute heights rather than the relative heights. This is done by setting the .gg.scale.limits[(min;max)] on the X scale.

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `dodge or `stack
  • `gap - Gap between bars as percent of width/height (i.e., 0.03 for 3%)
  • `align - Bar alignment
  • `sortByValue - Sort bars by y axis value (largest to smallest)

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a bar chart

See Also: .gg.scale.limits

Example: Load data and basic plot

     t: ([] x: 15#.Q.a; y: 10 + sums 15?-2 -1 1 2);

     .qp.hbar[t; `y; `x; ::]

Image

Example: Change colour and order by value

      .qp.hbar[t; `y; `x]
          .qp.s.geom[``fill`sortByValue!(::; `slategrey; 1b)]

Image

Example: Annotate with text labels and start at 0

     .qp.stack (
         .qp.hbar[t; `y; `x]
              .qp.s.geom[``fill`sortByValue!(::; `slategrey; 0b)];
         .qp.text[t; `y; `x; `y]
              .qp.s.geom[``offsetx`align`bold`size!(::;10;`middle;1b;11)])

Image

Example: Grouped

      t: raze { ([] cat:x; x: 15#.Q.a; y: 10 + sums 15?-2 -1 1 2)} each `cat1`cat2`cat3`cat4;

      .qp.hbar[t; `y; `x]
            .qp.s.aes[`fill; `cat]

Image

Example: Grouped and stacked

      .qp.hbar[t; `y; `x]
            .qp.s.aes[`fill`group; `cat`cat]
          , .qp.s.geom[``position!(::; `stack)]
          , .qp.s.scale[`fill; .gg.scale.colour.cat `puor]

Example: Grouped and dodged with custom y and fill scales


      .qp.hbar[select from t where x in "abcde"; `y; `x]
            .qp.s.aes   [`fill`group; `cat`cat]
          , .qp.s.geom  [``position`gap!(::; `dodge;0.05)]
          , .qp.s.scale [`fill; .gg.scale.colour.cat `brbg]
             // start y axis at 0
          , .qp.s.scale [`x; .gg.scale.limits[0 0N] .gg.scale.linear]

Image

.qp.hboxplot

Horizontal box plot showing median, first and third quartiles, farthest point within 1.5 times the interquartile range from the median on either side, and all outliers (points further than this).

  • X - Continuous value (value to summarize)
  • Y - Category (position along the vertical)

The Y column should be a category, and the X column continuous.

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a box plot

Example: Load data and basic categorical plot

      t : ([]x: raze 50#enlist 10?`5; y: 500?50; z: raze 50#'til 10);

      .qp.hboxplot[t; `y; `x; ::]

Image

Example: Basic numeric plot

      .qp.hboxplot[t; `y; `z; ::]

Image

.qp.heatmap

2D heatmap chart. By default, alpha is mapped to the count of the records in each bucket. This can be changed to map to anything else, or turned of with .qp.s.aes[`alpha; ::] in the settings.

Custom aggregations can be added and mapped as well (see examples below).

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a heatmap

Example: Load data and basic heatmap with angled x axis

     t : ([]
          c1:100000?20?`5; 
          c2:100000?50?`5; 
          x:5 * .st.gen.normal 100000; 
          y:sin .st.gen.normal 100000; 
          z:.st.gen.normal 100000);

     .qp.theme[`axis_tick_label_anchor_x`axis_tick_label_angle_x!(`left; 90)]
         .qp.heatmap[t; `c1; `c2; ::]

Image

Example: Continuous * categorical with fill colour

     .qp.heatmap[t; `x; `c2]
         .qp.s.geom[``fill!(::; 0x0070cd)]

Image

Example: Add a new aggregation over y and map to fill colour and bin counts

     .qp.heatmap[t; `x; `z]
         .qp.s.aggr[.st.a.count[] , .st.a.custom[`yout; `y; avg]]
         , .qp.s.aes[`fill; `yout]
         , .qp.s.aes[`alpha; `]
         , .qp.s.scale[`fill; .gg.scale.colour.gradient2[0f; `firebrick; 0xebebeb; `steelblue]]
         , .qp.s.binx[`c;50;0]
         , .qp.s.biny[`c;50;0]

Image

.qp.herrorbar

Horizontal error bar geometry.

  • X - first point of the interval
  • XEND - second point of the interval
  • YEND - position along the vertical

Series can be dodged (see examples below).

Aesthetic mappings (`.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `position - `dodge

Parameters:

Name Type Description
table table
x symbol column name
xend symbol column name
y symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table tree specifying an interval chart

Example: Stacking with a point

      t:update l1:x-.25,l2:x+.25 from 
          0!select max x by y, y2 from 
          ([]x:.st.gen.normal 100;y:100?`a`b`c`d; y2:100?`e`f`g`h);

      .qp.stack (
         .qp.herrorbar[select from t where y2=`e; `l1; `l2; `y; ::];
         .qp.point   [select from t where y2=`e; `x; `y]
             .qp.s.geom[``size!(::;5)])

Image

Example: Dodged error bars stacked with bars

     .qp.stack (
         .qp.hbar[t;`x;`y] 
             .qp.s.aes[`group`fill; `y2`y2] , 
             .qp.s.scale[`fill; .gg.scale.colour.cat `rdylbu] ,
             .qp.s.geom[``position!(::;`dodge)];
         .qp.herrorbar[t;`l1;`l2;`y] 
             .qp.s.aes[`group; `y2] , 
             .qp.s.geom[``position`fill!(::;`dodge;`black)])

Image

.qp.hhistogram

Horizontal histogram chart - the length of each bar depicts the observations of a distinct value.

  • X - position along the vertical.

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `dodge or `stack
  • `sortByValue - Sort bars by y axis value (largest to smallest)

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification tree

Example: Load data and continuous hhistogram

     t: raze {[category; num]
         ([] 
             c1: category; 
             x: 2 * (-2 + rand 4f) + .st.gen.normal num; 
             y: .st.gen.normal num; 
             z:  {acos[-1] * x % max x} .st.gen.normal num) 
         }'[`a`b`c`d`e; 10000+5?35000];

     .qp.hhistogram[t; `c1; ::]

Image

Example: Change the scale to start at 0 and order by value


     .qp.hhistogram[t; `c1]
         .qp.s.scale[`x; .gg.scale.limits[0 0N] .gg.scale.linear] ,
         .qp.s.geom[``sortByValue!(::;1b)]

Image

Example: Continuous axis with fill colour

     .qp.hhistogram[t; `x]
         .qp.s.geom[``fill!(::; 0x0070cd)]

Image

Example: Dodge based on another column

     .qp.hhistogram[t; `x]
         .qp.s.scale[`x; .gg.scale.limits[0 0N] .gg.scale.linear]
                      // Requires a 2D bin transform rather than a 1D
         , .qp.s.stat[ .gg.stat.bin2d[`x`c1; ::; ::; .st.a.count[]; ::] ]
         , .qp.s.geom[`position`gap!(`dodge; 0)]
         , .qp.s.aes[`group; `c1]
         , .qp.s.aes[`fill; `c1]

Image

Example: Add an explicit fill scale

     .qp.hhistogram[t; `x]
         .qp.s.scale[`x; .gg.scale.limits[0 0N] .gg.scale.linear]
                      // Requires a 2D bin transform rather than a 1D
         , .qp.s.stat[ .gg.stat.bin2d[`x`c1; ::; ::; .st.a.count[]; ::] ]
         , .qp.s.geom[``position!(::; `dodge)]
         , .qp.s.aes[`group; `c1]
         , .qp.s.aes[`fill; `c1]
         , .qp.s.scale[`fill; .gg.scale.colour.cat `pubugn]

Image

Example: Change from a stack to a dodge with a blue scale

     .qp.hhistogram[t; `x]
         .qp.s.scale[`x; .gg.scale.limits[0 0N] .gg.scale.linear]
         , .qp.s.stat[ .gg.stat.bin2d[`x`c1; ::; ::; .st.a.count[]; ::] ]
         , .qp.s.geom[``position!(::; `stack)]  // <- changed to stack
         , .qp.s.aes[`group; `c1]
         , .qp.s.aes[`fill; `c1]
         , .qp.s.scale[`fill; .gg.scale.colour.cat `pubugn]

Image

Example: Stack with an binned line of another continuous column using 100 bins

     .qp.stack (
         .qp.hhistogram[t; `x]
             .qp.s.scale[`x; .gg.scale.limits[0 0N] .gg.scale.linear]
             , .qp.s.stat[ .gg.stat.bin2d[`x`c1; (`c;100;0); ::; .st.a.count[]; ::] ]
             , .qp.s.biny[`x;100;0]
             , .qp.s.geom[``position`gap!(::;`stack;0)]
             , .qp.s.aes[`group; `c1]
             , .qp.s.aes[`fill; `c1]
             , .qp.s.scale[`fill; .gg.scale.colour.cat `bugn];
         .qp.path[t;  `count__; `y]
             .qp.s.stat[ .gg.stat.bin1d[`y; (`c;100;0); .st.a.count[]; ::] ] 
             , .qp.s.geom[``fill`size!(::; 0xcd0000;1.5)])

Image

.qp.hinterval

Horizontal interval chart - an interval between two numbers on the X axis for each value along the Y axis.

  • X - first point of the interval
  • XEND - second point of the interval
  • Y - position along the vertical

Series can be dodged (see examples below).

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `dodge
  • `gap - Gap between bars as percent of width/height (i.e., 0.03 for 3%)
  • `align - Bar alignment

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
xend symbol column name
y symbol column name
settings dict settings for the visual (geom/bins/etc)

Returns:

Type Description
table tree specifying an hinterval chart

Example: Load data and basic plot

      t: ([] x: `a`b`c`d`e`f`g; y1: -50+7?100; y2: 50+7?100);
      .qp.hinterval[t;  `y1; `y2;`x; ::]

Image

Example: Filled

      .qp.hinterval[t; `y1; `y2; `x]
          .qp.s.geom[``fill!(::;0x0070cd)]

Image

Example: Grouped and dodged

      t:  raze {[category;num] ([] 
             c1: category; 
             c2: num?`cat1`cat2`cat3;
             x: (-2 + rand 4f) + .st.gen.normal num; 
             y: .st.gen.normal num) 
         }'[`a`b`c`d`e; 10000+5?35000];
      t: select y1: min x, y2: max x by c1, c2 from t;

      .qp.hinterval[t; `y1; `y2; `c1]
            .qp.s.aes[`fill; `c2]
          , .qp.s.scale[`fill; .gg.scale.colour.cat10]
          , .qp.s.aes[`group;`c2]
          , .qp.s.geom[``position!(::; `dodge)]

Image

Example: Positive/negative bar charts

     t: ([]y:0; y2: (.st.gen.normal[30] % 5) + sin 3 * acos[-1] * til[30] % 30; x:til 30);
     t: update pos:y2>=0 from t;

     .qp.hinterval[t; `y; `y2; `x]
           .qp.s.aes[`fill; `pos]
         , .qp.s.scale[`fill; .gg.scale.colour.cat 01b!(0xcd4000; 0x0070cd)]

Image

Example: Stack a moving average line


     .qp.stack (
         .qp.hinterval[t; `y; `y2; `x]
               .qp.s.aes[`fill; `pos]
             , .qp.s.scale[`fill; .gg.scale.colour.cat 01b!(0xcd4000; 0x0070cd)]
             , .qp.s.geom[``alpha!(::;0x7f)];
         .qp.path[update y2: 10 mavg y2 from t; `y2; `x]
               .qp.s.geom[``size!(::;2)])

Image

.qp.histogram

Vertical histogram chart - the height of each bar depicts the number of observations of each distinct value

  • X - the position along the X axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `dodge or `stack
  • `sortByValue - Sort bars by y axis value (largest to smallest)

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification tree

Example: Load data and continuous histogram

     t: raze {[category; num]
         ([] 
             c1: category; 
             x: 2 * (-2 + rand 4f) + .st.gen.normal num; 
             y: .st.gen.normal num; 
             z:  {acos[-1] * x % max x} .st.gen.normal num) 
         }'[`a`b`c`d`e; 10000+5?35000];

     .qp.histogram[t; `c1; ::]

Image

Example: Change the scale to start at 0 and order by value


     .qp.histogram[t; `c1]
         .qp.s.scale[`y; .gg.scale.limits[0 0N] .gg.scale.linear] ,
         .qp.s.geom[``sortByValue!(::;1b)]

Image

Example: Continuous axis with fill colour

     .qp.histogram[t; `x]
         .qp.s.geom[``fill!(::; 0x0070cd)]

Image

Example: Dodge based on another column

     .qp.histogram[t; `x]
         .qp.s.scale[`y; .gg.scale.limits[0 0N] .gg.scale.linear]
                      // Requires a 2D bin transform rather than a 1D
         , .qp.s.stat[ .gg.stat.bin2d[`x`c1; ::; ::; .st.a.count[]; ::] ]
         , .qp.s.geom[`position`gap!(`dodge; 0)]
         , .qp.s.aes[`group`fill; `c1`c1]

Image

Example: Add an explicit fill scale

     .qp.histogram[t; `x]
         .qp.s.scale[`y; .gg.scale.limits[0 0N] .gg.scale.linear]
                      // Requires a 2D bin transform rather than a 1D
         , .qp.s.stat[ .gg.stat.bin2d[`x`c1; ::; ::; .st.a.count[]; ::] ]
         , .qp.s.geom[``position!(::; `dodge)]
         , .qp.s.aes[`group`fill; `c1`c1]
         , .qp.s.scale[`fill; .gg.scale.colour.cat `pubugn]

Image

Example: Change from a stack to a dodge with a blue scale

     .qp.histogram[t; `x]
         .qp.s.scale[`y; .gg.scale.limits[0 0N] .gg.scale.linear]
         , .qp.s.stat[ .gg.stat.bin2d[`x`c1; ::; ::; .st.a.count[]; ::] ]
         , .qp.s.geom[``position!(::; `stack)]  // <- changed to stack
         , .qp.s.aes[`group`fill; `c1`c1]
         , .qp.s.scale[`fill; .gg.scale.colour.cat `pubugn]

Image

Example: Stack with an binned line of another continuous column using 100 bins

     .qp.stack (
         .qp.histogram[t; `x]
             .qp.s.scale[`y; .gg.scale.limits[0 0N] .gg.scale.linear]
             , .qp.s.stat[ .gg.stat.bin2d[`x`c1; (`c;100;0); ::; .st.a.count[]; ::] ]
             , .qp.s.binx[`c;100;0]
             , .qp.s.geom[``position`gap!(::;`stack;0)]
             , .qp.s.aes[`group`fill; `c1`c1]
             , .qp.s.scale[`fill; .gg.scale.colour.cat `bugn];
         .qp.path[t;  `y; `count__]
             .qp.s.stat[ .gg.stat.bin1d[`y; (`c;100;0); .st.a.count[]; ::] ] 
             , .qp.s.geom[``fill`size!(::; 0xcd0000;1.5)])

Image

.qp.hline

Horizontal straight line.

  • Y - vertical position of the line

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size
  • `dashed - Solid or dashed lines

Parameters:

Name Type Description
y symbol y position
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a bar chart

Example: Basic horizontal rules


 t: ([]x: .st.gen.normal 100000; y: .st.gen.normal 100000);

 .qp.stack (
     .qp.point[t; `x; `y] .qp.s.geom[``alpha!(::; 0x2f)];
     .qp.hline[-2] .qp.s.geom[``fill!(::; `red)];
     .qp.hline[2]  .qp.s.geom[``fill!(::; `red)])

Image

Example: Adding in vertical rules


 .qp.stack (
     .qp.point[t; `x; `y] .qp.s.geom[``alpha!(::; 0x2f)];
     .qp.vline[0]  .qp.s.geom[``fill!(::; `red)];
     .qp.hline[-2] .qp.s.geom[``fill!(::; `red)];
     .qp.hline[2]  .qp.s.geom[``fill!(::; `red)])

Image

.qp.interval

Vertical interval chart - an interval between two numbers on the Y axis for each value along the X axis.

  • X - position along the horizontal
  • Y - first point of the interval
  • YEND - second point of the interval

Series can be dodged (see examples below).

Aesthetic mappings (`.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `position - `dodge
  • `gap - Gap between bars as percent of width/height (i.e., 0.03 for 3%)
  • `align - Bar alignment

Parameters:

Name Type Description
table table
x symbol column name
y symbol column name
yend symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table tree specifying an interval chart

Example: Load data and basic plot

      t: ([] x: `a`b`c`d`e`f`g; y1: -50+7?100; y2: 50+7?100);
      .qp.interval[t; `x; `y1; `y2; ::]

Image

Example: Filled

      .qp.interval[t; `x; `y1; `y2]
          .qp.s.geom[``fill!(::;0x0070cd)]

Image

Example: Grouped and dodged

      t:  raze {[category;num] ([] 
             c1: category; 
             c2: num?`cat1`cat2`cat3;
             x: (-2 + rand 4f) + .st.gen.normal num; 
             y: .st.gen.normal num) 
         }'[`a`b`c`d`e; 10000+5?35000];
      t: select y1: min x, y2: max x by c1, c2 from t;

      .qp.interval[t; `c1; `y1; `y2]
            .qp.s.aes[`fill; `c2]
          , .qp.s.scale[`fill; .gg.scale.colour.cat10]
          , .qp.s.aes[`group;`c2]
          , .qp.s.geom[``position!(::; `dodge)]

Image

Example: Positive/negative bar charts

     t: ([]y:0; y2: (.st.gen.normal[30] % 5) + sin 3 * acos[-1] * til[30] % 30; x:til 30);
     t: update pos:y2>=0 from t;

     .qp.interval[t; `x; `y; `y2]
           .qp.s.aes[`fill; `pos]
         , .qp.s.scale[`fill; .gg.scale.colour.cat 01b!(0xcd4000; 0x0070cd)]

Image

Example: Stack a moving average line


     .qp.stack (
         .qp.interval[t; `x; `y; `y2]
               .qp.s.aes[`fill; `pos]
             , .qp.s.scale[`fill; .gg.scale.colour.cat 01b!(0xcd4000; 0x0070cd)]
             , .qp.s.geom[``alpha!(::;0x7f)];
         .qp.line[update y2: 10 mavg y2 from t; `x; `y2]
               .qp.s.geom[``size!(::;2)])

Image

.qp.line

Line chart - draw a line from the left to the right (in the order of the domain).

  • X - position along the X axis
  • Y - position along the Y axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size
  • `group - Grouping (break lines in categories based on this label)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size
  • `dashed - Solid or dashed line
  • `decorations - Add or remove points from the line (default: false)

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table for a line chart

See Also: .qp.path

Example: Load data and basic chart

     t : raze { 
         ([] date: .z.d + til 800; 
             price: sums?[800?1.<0.5;-1;1];
             sym: x) 
     } each `a`b`c;

     .qp.line[select med price by date.month from t; `month; `price; ::]

Image

Example: Change fill colour and add points


     .qp.line[select med price by date.month from t; `month; `price]
         .qp.s.geom[``fill`decorations!(::; 0x0070cd; 1b)]

Image

Example: Group lines by symbol

     .qp.line[select med price by date.month, sym from t; `month; `price]
           .qp.s.geom[``decorations!(::; 1b)]
         , .qp.s.aes[`group`fill; `sym`sym]

Image

Example: Increase granularity and group

     .qp.line[t; `date; `price]
           .qp.s.geom[``fill!(::; 0x0070cd)]
         , .qp.s.aes[`group`fill; `sym`sym]

Image

Example: Draw a moving average over a line

     .qp.stack (
         .qp.line[select from t where sym = `a; `date; `price]
             .qp.s.geom[``fill`alpha!(::; 0x0070cd; 0x9f)];
         .qp.line[update price: 30  mavg price from select from t where sym = `a; `date; `price]
             .qp.s.geom[``fill`size!(::; 0xcd3000; 1.5)];
         .qp.line[update price: 100 mavg price from select from t where sym = `a; `date; `price]
             .qp.s.geom[``size!(::; 1.5)])

Image

.qp.matrix

Convert a matrix of numbers into a tile grid filled by the value in each matrix cell

Parameter:

Name Type Description
x number[][]

Example:


      m: x mod/:x:1+til 1000;
      /=> 0 0 0 0 0 ..
      /=> 1 0 1 0 1 ..
      /=> 1 2 0 1 2 ..      
      /=> 1 2 3 0 1 ..
      /=> 1 2 3 4 0...
      /=> ...

      .qp.matrix m

Image

.qp.path

Path chart - like a line chart, but drawn in order of the data rather than in order of the domain.

  • X - position along the X axis
  • Y - position along the Y axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Outline size
  • `group - Grouping

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Outline size

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table for a path chart

See Also: .qp.line

Example: Load data and basic chart

     t: ([] x: sin 4 * acos[-1] * %[;99] til 100; 
            y: cos 4 * acos[-1] * %[;99] til 100);

     .qp.path[t; `x; `y; ::]

Image

Example: Basic example

     t: ([] x: til[100] * sin 4 * acos[-1] * %[;99] til 100; 
            y: til[100] * cos 4 * acos[-1] * %[;99] til 100;
            t: til 100);

     .qp.path[t; `x; `y; ::]

Image

Example: Add fill colour mapping

     .qp.path[t; `x; `y]
           .qp.s.aes[`fill; `t]
         , .qp.s.scale[`fill; .gg.scale.colour.gradient[`firebrick; `steelblue]]

Image

Example: Add line size mapping

     .qp.path[t; `x; `y]
           .qp.s.aes[`fill; `t]
         , .qp.s.scale[`fill; .gg.scale.colour.gradient[`firebrick; `steelblue]]
         , .qp.s.aes[`size; `t]
         , .qp.s.scale[`size; .gg.scale.line.size[1; 6]]

Image

.qp.plot

Create a plot of the indicated columns from a table.

Creates a best-guess plot based on the types of the columns. If more than two columns are specified, a plot of pairs of all columns will be created.

Only the lower triangle of pairs will be plotted (this covers all relationships). The upper triangle will display the correlation of each continuous pair. If either pair is categorical, the correlation will be empty for that pair. See the examples below.

Parameters:

Name Type Description
table table data to be visualized
cs symbol[] list of columns to be visualized
settings null | dict settings for the visual (geom/etc)

Returns:

Type Description
table specification table

Example: A single column - histogram

 t: ([]
     num1:  .st.gen.normal 1000; 
     num2:  {sin acos[-1] * x % max x} .st.gen.normal 1000; 
     num3:  {cos acos[-1] * x % max x} .st.gen.normal 1000; 
     cat1:  1000?5?`5;
     cat2:  1000?5?`5);

 .qp.plot[t; `num1; ::]

Image

Example: Two columns - scatter, boxplot, or heatmap

 .qp.plot[t; `num1`num2; ::]

Image

Example: Three columns - a grid of relationships

 .qp.plot[t; `num1`num2`cat1; ::]

Image

Example: All columns

 .qp.plot[t; (); ::]

Image

Example: Change fill colour

 .qp.plot[t; ()]
     .qp.s.geom[``fill!(::;0x0070cd)]

Image

.qp.point

Scatter chart - basic point geometry.

  • X - position along the X axis
  • Y - position along the Y axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping
  • `size - Circle size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `size - Circle size
  • `shape - One of `circle`square`triangle
  • `jitterx - Jitter x position (percent of canvas)
  • `jittery - Jitter y position (percent of canvas)

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table for a scatter chart

See Also: .qp.scatter

Example: Load data and basic chart

     t:      ([]x:10000?1.;y:10000?1.);
     t:      update z: {.gg.proj.proj[(min x;max x);0 5000000;x]} sin[x]*sin[y] from t;
     labels: ("0-1M";"1-2M";"2-3M";"3-4M";"4-5M");
     t:      update fillcol: labels("f"$1000000*til 5)?1000000 xbar z from t;

     .qp.point[t; `x; `y; ::]

Image

Example: Add a fill colour


      .qp.point[t; `x; `y]
          .qp.s.geom[``fill!(::;`steelblue)]

Image

Example: Add a fil mapping


     .qp.point[t; `x; `y]
        .qp.s.aes[`fill; `fillcol]
      , .qp.s.scale[`fill; .gg.scale.colour.cat `blues]

Image

Example: Use stroke rather than fill


     .qp.point[t; `x; `y]
        .qp.s.aes[`colour; `fillcol]
      , .qp.s.scale[`colour; .gg.scale.colour.cat `blues] 
      , .qp.s.geom[`size`alpha`colour`strokewidth!(4; 0x00; `firebrick; .5)]

Image

Example: Adding x and/or y jitter as percentage of canvas


     t: ([]x: sums?[45?1.<0.5;-1;1]; y: sums?[45?1.<0.5;-1;1]);

     .qp.point[500#([]x:0 0 1 1;y:0 1 0 1);`x;`y] 
         .qp.s.geom[``jitterx`jittery!(::;0.1;0.3)]

Image

.qp.point3D

3D Scatter chart - basic 3D point geometry.

  • X - position along the X axis
  • Y - position along the Y axis
  • Z - position along the Z axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping
  • `size - Circle size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `size - Circle size

The default viewing angle is an isometric view. The viewing angle can be changed by using .qp.s.coord to set a new cube coordinate system with the desired azimuth and altitude.

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
z symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table for a 3D scatter chart

See Also: .gg.coords.cube

Example: Load data and basic chart

      t: ([]x: sums?[45?1.<0.5;-1;1]; y: sums?[45?1.<0.5;-1;1]; z: y: sums?[45?1.<0.5;-1;1]);

      .qp.point3D[t; `x; `y; `z; ::]

Image

Example: Add a fill colour

      .qp.point3D[t; `x; `y; `z]
          .qp.s.geom[enlist[`fill]!enlist `steelblue]

Image

Example: Change the size, opacity, and fill

      .qp.point3D[t; `x; `y; `z]
          .qp.s.geom[`size`alpha`colour`fill!(4; 0x20; `firebrick; `steelblue)]

Image

Example: Change the viewing angle

      .qp.point3D[t; `x; `y; `z]
            .qp.s.geom[`size`fill!(3; `firebrick)]
          , .qp.s.coord[.gg.coords.cube . 2#4*atan[1]%3]

Image

Example: Grid in multiple views

     s: {x*x};
     t: 5+`x`y`z!/:ps,'{ sin[sqrt s[x]+s y] % sqrt s[x]+s y } .' ps:({x cross x} -60+til 120) % 16;

     .qp.theme[``legend_use!(::;0b)]
         .qp.grid[0N 0N] (
             .qp.point3D[t; `x; `y; `z]
                 .qp.s.aes   [`fill`alpha; `z`count__] ,
                 .qp.s.geom  [``alpha`size!(::;0x7f;1)] ,
                 .qp.s.stat  [ .gg.stat.binNd[`x`y`z; ((`c;60;0);(`c;60;0);(`c;60;0)); .st.a.count[]; ``center!(::;1b)] ];
             .qp.point3D[t; `x; `y; `z]
                 .qp.s.aes[`fill`alpha; `z`count__] ,
                 .qp.s.geom  [``alpha`size!(::;0x7f;1)] ,
                 .qp.s.coord [.gg.coords.cube[neg 1%sqrt 2; 2] ] ,
                 .qp.s.stat  [ .gg.stat.binNd[`x`y`z; ((`c;60;0);(`c;60;0);(`c;60;0)); .st.a.count[]; ``center!(::;1b)] ];
             .qp.point[t;`x;`y] 
                 .qp.s.geom  [``alpha`size!(::;0x7f;1)] ,
                 .qp.s.aes   [`fill;`z];
             .qp.point[t;`x;`z] 
                 .qp.s.geom  [``alpha`size!(::;0x7f;1)] ,
                 .qp.s.aes   [`fill;`z])

Image

.qp.polar.pie

Pie chart.

  • X - Categories to aggregate and plot (eg, select count i by X from t will be done automatically)

Aesthetic mappings supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size

A simple wrapper around the following GG for convenience:

    .qp.theme[``aspect_ratio`axis_use_x`axis_use_y!(::;`square;0b;0b)] 
        .qp.bar[table;`const__;`count__] 
              .qp.s.stat  [.gg.stat.pie[x; .st.a.count[]]]
            , .qp.s.aes   [`group;x]
            , .qp.s.aes   [`fill;x]
            , .qp.s.scale [`fill; .gg.scale.colour.cat10]
            , .qp.s.scale [`y; .gg.scale.linear]
            , .qp.s.scale [`x; .gg.scale.limits[-0.0001 0.0001] .gg.scale.linear]
            , .qp.s.geom  [``position!(::;`stack)] 
            , .qp.s.coord [.gg.coords.polar]

Parameters:

Name Type Description
table table data to be visualized
x symbol column of categories to pie
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a pie chart

See Also: .gg.scale.limits

Example: Load data and basic pie

      t : ([]x: raze 5#enlist 10?`5; y: 50?5; z: raze 5#'til 10);

      .qp.polar.pie[t;`y;::]

Image

Example: Add an explicit fill scale


      .qp.polar.pie[t;`y] .qp.s.scale[`fill; .gg.scale.colour.cat `rdylbu]

Image

.qp.polygon

Add a polygon geometry for each record of the table. The xs and ys should be columns of nested numbers.

For example ([]xs: (1 2 3; 4 5 6); ys: (1 2 1; 3 4 3)) would define two triangles (one per record).

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `clip - Whether to omit polygons if not entirely within bounds when zooming (default true)

Parameters:

Name Type Description
table table data to be visualized
xs symbol column name
ys symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table

Example: Load data and basic polygon

     t: ([]x: enlist 100 40 190 10 160; y: enlist 198 - 10 198 78 78 198);

     // Each polygon is defined by a *single* record
     .qp.polygon[t; `x; `y; ::]

Image

Example: Add a stroke property and include clipped geometries when zooming

     .qp.polygon[t; `x; `y]
         .qp.s.geom[`fill`alpha`colour`clip!(`yellow; 0x80; `black; 0b)]

Image

Example: Radar chart

     t  : raze{t:([]x:til 7;y:10+7?100;Category:x); t,first[t],(1#`x)!1#7}each `A`B;
     t2 : select x, y by Category from t;
     .qp.theme[``aspect_ratio!(::;`square)]
         .qp.stack (
             .qp.polygon[t2;`y;`x]
                   .qp.s.geom  [``alpha`colour!(::;0x30;`white)]
                 , .qp.s.scale [`y; .gg.scale.format[{.Q.a x}] .gg.scale.breaks[til 9] .gg.scale.linear]
                 , .qp.s.aes   [`fill; `Category]
                 , .qp.s.scale [`fill; .gg.scale.colour.cat10]
                 , .qp.s.coord [.gg.coords.polarn 2];
             .qp.point[t; `y; `x]
                   .qp.s.aes   [`fill; `Category]
                 , .qp.s.scale [`fill; .gg.scale.colour.cat10])

Image

.qp.quantile

Create a quantile plot of a single column. Shows a distribution of values over a single variable.

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `size - Point size
  • `strokewidth - Outline size

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table

Example: Load data and basic plot

      t : ([]x: 45?100);

      .qp.quantile[t; `x; ::]

Image

.qp.rect

Rectangle chart - draw a rectangle given it's bounds as two points for each record.

  • X - first position along the X axis
  • Y - first position along the Y axis
  • XEND - second position along the X axis
  • YEND - second position along the Y axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
xend symbol column name
yend symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table tree specifying a segment chart

See Also: .qp.tile

Example: Load data and basic chart

     t : ([]x1: 0 10; y1: 0 10; x2: 5 15; y2: 5 15);

     .qp.rect[t; `x1; `y1; `x2; `y2; ::]

Image

Example: Add custom geom properties

     .qp.rect[t; `x1; `y1; `x2; `y2]
            .qp.s.geom[`fill`alpha`colour`strokewidth!(`firebrick; 0x7f; `orange; 10)]

Image

Example: Treemap

     t: ([]Sector: 10?`8;MarketValue: 10?100);
     positions: .qp.treemap.layout[t; `Sector; `MarketValue; ::];

     .qp.theme[.gg.theme.blank]
          .qp.rect[positions;`x__;`y__;`x2__;`y2__]
              .qp.s.aes[`fill; `Sector] ,
              .qp.s.geom[``colour!(::; 0xffffff)]

Image

.qp.ribbon

Add a ribbon geometry - similar to an area geometry, with a defined minimum value as well rather than 0.

  • X - position along the Y axis
  • Y - first point along the vertical interval
  • YEND - second point along the vertical interval

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `group - Grouping

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
yend symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table

Example: Load data and basic chart

     t: raze { 
         ([] date: .z.d + til 800; 
             price: .st.gen.normal[800] + sums?[800?1.<0.5;-1;1];
             sym: x) 
     } each `a`b`c`d;

     .qp.ribbon[select min price, max price by date.month from t; `month; `price; `price1]
         .qp.s.geom[``fill`alpha!(::; 0x0070cd; 0xaf)]

Image

Example: Increase granularity and add an average line

     .qp.stack (
         .qp.ribbon[select min price, max price by date from t; `date; `price; `price1]
             .qp.s.geom[``fill`alpha!(::; 0x0070cd; 0xaf)];
         .qp.line[select avg price by date from t; `date; `price; ::])

Image

Example: Draw points outside a region


     t2: select avg[price] - 1 * dev price, avg[price] + 1 * dev price by date from t;
     d:  exec (avg[price] - 1.5 * dev price; avg[price] + 1.5 * dev price) by date from t;

     .qp.stack (
         .qp.ribbon[t2; `date; `price; `price1]
             .qp.s.geom[``fill`alpha!(::; 0x0070cd; 0xaf)];
         .qp.line[select avg price by date from t; `date; `price]
             .qp.s.geom[``fill`size!(::; `white; 2)];
         .qp.point[select from t where not price within' d[date]; `date; `price]
             .qp.s.geom[``fill!(::; 0xcd3000)])

Image

Example: split into multiple groups

     t : ([] date: til 1000; 
                  start: sums?[1000?1.<0.5;-1;1]; 
                  end: sums?[1000?1.<0.5;-1;1];
                  volume: 10+1000?10; 
                  sym: `a),
              ([] date: til 1000; 
                  start: sums?[1000?1.<0.5;-1;1]; 
                  end: sums?[1000?1.<0.5;-1;1];
                  volume: 10+1000?10; 
                  sym: `b),
              ([] date: til 1000; 
                  start: sums?[1000?1.<0.5;-1;1]; 
                  end: sums?[1000?1.<0.5;-1;1];
                  volume: 10+1000?10; 
                  sym: `c);

     .qp.ribbon[t; `date; `start; `end]
                .qp.s.aes     [`fill; `sym]
              , .qp.s.scale [`fill; .gg.scale.colour.cat10]
              , .qp.s.aes   [`group; `sym]
              , .qp.s.geom  [``alpha!(::; 0x7f)]

Image

.qp.scatter

Scatter chart - basic point geometry. See .qp.point.

Parameters:

Name Type Description
table table data to be visualized
x symbol column name
y symbol column name
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table for a scatter chart

See Also: .qp.point

.qp.segment

Segment chart. Draw a line between two points (defined by four columns) for every record.

  • X - horizontal position of the first point
  • Y - vertical position of the first point
  • XEND - horizontal position of the last point
  • YEND - vertical position of the last point

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size
  • `dashed - Solid or dashed line

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
xend symbol x end column
yend symbol y end column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table tree specifying a segment chart

Example: Load data and basic chart

      t : ([]x1: 0 10; y1: 0 10; x2: 5 15; y2: 5 15);

      .qp.segment[t; `x1; `y1; `x2; `y2; ::]

Image

Example: Add some geom properties

 .qp.segment[t; `x1; `y1; `x2; `y2]
     .qp.s.geom[`fill`size!(`steelblue; 10)]

Image

Example: Step charts created using segments

 // original values
 points: ([]x:til 10;y:10?45);
 // create steps for segments
 steps:  raze {flip `x`y`x2`y2!(x`x`x2; x`y; x`x2; x`y`y2)} each 
     points,'select x2:next x, y2:next y from points;

 .qp.title["Example step chart"]
     .qp.stack (
         // step lines
         .qp.segment[steps; `x; `y; `x2; `y2; ::];
         // original points
         .qp.point[points;`x;`y] .qp.s.geom[``size`fill!(::;3;0xff0000)])

Image

Example: Draw lines out of a single point

     t:         (0 0;) @' flip -10 + 20 20?\:20;
     quadrant:  {$[all 0<=x,y;1;(0>x)&0<=y;2;(0>x)&0>y;3;4]};
     angles:    {atan (%). abs reverse y-x}./:t;
     quadrants: {quadrant . y-x} ./: t;
     t:         update q: quadrants from `x`y`x2`y2!/:raze each t;

     .qp.segment[t; `x; `y; `x2; `y2]
         .qp.s.aes[`fill; `q] ,
         // Override the default numeric colour scale with a categorical one
         .qp.s.scale[`fill; .gg.scale.colour.cat10]

Image

.qp.smooth

Various scatterplot smoothers.

  • NOTE - loess is a local regression technique that, while flexible, can be computationally intensive. Try sampling the data first.

Parameters:

Name Type Description
table table
x symbol column
y symbol column
opts dict options for which smooth to use and smooth arguments
settings dict | null settings for the visual (geom/bins/etc)

Returns:

Type Description
table specification table

Example: Show a line on the average price over the diamonds data

     t : ([] carat: til 100; 
             price: {[c;x]sum c*x xexp til count c}[1 4 -3 2] each til 100);

     .qp.stack (
         .qp.point[t; `carat; `price; ::];
         .qp.smooth[t; `carat; `price; `stat`degree!(`lsq;0); ::])

Image

Example: Fit the diamonds data to a degree-3 polynomial

     .qp.stack (
         .qp.point[t; `carat; `price; ::];
         .qp.smooth[t; `carat; `price; `stat`degree!(`lsq;3); ::])

Image

Example: Use default loess locally weighted regression on a random sample

     t : ([] carat: til 1000;
             price: sums?[1000?1.<0.5;-1;1]);

     .qp.stack (
         .qp.point[t; `carat; `price; ::];
         .qp.smooth[1000?t; `carat; `price; ::; ::])

Image

Example: Use loess with a specified bandwidth of 0.45

     .qp.stack (
         .qp.point[t; `carat; `price; ::];
         .qp.smooth[1000?t; `carat; `price; enlist[`bandwidth]!enlist 0.45; ::])

Image

Example: Use loess with a specified bandwidth of 0.45 and delta of 0.1 on all data (not sampled)

     .qp.stack (
         .qp.point[t; `carat; `price; ::];
         .qp.smooth[t; `carat; `price; `force`delta`bandwidth!(1b; 0.1; 0.45); ::])

Image

.qp.text

Text/annotation charts. Text will be left-aligned by default, but can be changed (see examples below).

  • X - position along the X axis
  • Y - position along the Y axis

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Text size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Text size
  • `angle - Text angle
  • `offsetx - Offset from the x position in pixels
  • `offsety - Offset from the y position in pixels
  • `bold - Use bold text
  • `italic - Use italic text
  • `align - Text alignment (`left, `middle, `right)

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
label symbol text column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification table for a text chart

Example: Load data and basic chart

      t: ([]x: til 45; y: 45?45);

      .qp.text[t; `x; `y; `y; ::]

Image

Example: Add a fill colour

      .qp.text[t; `x; `y; `y]
          .qp.s.geom[enlist[`fill]!enlist `steelblue]

Image

Example: Change the opacity mapping

      .qp.text[t; `x; `y; `y]
          .qp.s.geom[`size`fill!(8; `firebrick)]
          , .qp.s.aes[`alpha; `y]
          , .qp.s.scale[`alpha; .gg.scale.alpha[50;255]]

Image

Example: Change the alignment to be middle aligned

      .qp.text[t; `x; `y; `y]
          .qp.s.geom[`size`fill`align!(8; `firebrick; `middle)]
          , .qp.s.aes[`alpha; `y]
          , .qp.s.scale[`alpha; .gg.scale.alpha[50;255]]

Image

.qp.tile

Tile plot. Default width and height is 1, but can be changed (see examples below).

  • X - left edge of the tile
  • Y - bottom of the tile

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `group - Grouping (combined with `position geom settings)

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `colour - Outline colour
  • `strokewidth - Outline size
  • `width - Width
  • `height - Height
  • `valign - Vertical alignment (`bottom`top`middle)
  • `halign - Horizontal alignment (`right`left`middle)
  • `gap - gap between tiles as percentage of width/height (for example, 0.03 for 3%)

Parameters:

Name Type Description
table table data to be visualized
x symbol x column
y symbol y column
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table tile plot specification

See Also: .qp.rect

Example: Load data and basic chart

      t : ([]x: 0 10; y: 0 10);

     .qp.tile[t; `x; `y; ::]

Image

Example: Change width and height

     .qp.tile[t; `x; `y]
          .qp.s.geom[`width`height!5 5]

Image

Example: Correlation matrix


     t:  flip raze {enlist[x]!enlist sums 1000?-1 1} each `$/:10#.Q.a;
     t2: `x`y`r!/:{ x ,' (cor) .' t x } (cross) . 2#enlist cols t;

     .qp.tile[t2; `x; `y]
         .qp.s.aes[`fill; `r] ,
         .qp.s.scale[`fill; .gg.scale.limits[-1 1] .gg.scale.colour.gradient2[0f; `red; 0xcbcbcb; 0x0070cd]]

Image

.qp.vector

Directed lines - draw a line from one point to another with an arrow indicating direction.

  • X - horizontal position of the first point
  • Y - vertical position of the first point
  • XEND - horizontal position of the last point
  • YEND - vertical position of the last point

This geometry is composes .qp.segment and .qp.point. See the help pages for those geometries for which aesthetics and geom options can be passed to each.

Parameters:

Name Type Description
t table data to be visualized
x1 symbol x column
y1 symbol y column
x2 symbol x column
y2 symbol y column
segsettings dict | null settings for the arrow
nodesettings dict | null settings for the line segment

Returns:

Type Description
table specification table for a vector geometry

See Also: .qp.point

Example: Basic vectors

      t : ([]x1: 0 10; y1: 0 10; x2: 5 15; y2: 5 15; c:2?`8);

     .qp.vector[5?t; `x1; `y1; `x2; `y2; ::; ::]

Image

Example: Styled vectors

     .qp.vector[t; `x1; `y1; `x2; `y2; 
         .qp.s.aes[`fill; `c] , .qp.s.geom[``dashed!(::;1b)];
         ::]

Image

Example: Network

     c  : `a`b`c`d`e`f`g`h`i;
     t  : `a`b!/:raze{-1_x ,' next x} each 0N 3#c;
     t ,: `a`b!/:raze{-1_x ,' next x} each flip 0N 3#c;

     layout: .qp.network.layout[t; `a; `b; ::];

     .qp.theme[.gg.theme.blank]
         .qp.vector[layout;`px__;`py__;`ppx__;`ppy__;::;]
             .qp.s.geom[``size!(::;3)]

Image

.qp.vline

Vertical straight line.

  • X - horizontal position of the line

Aesthetic mappings (.qp.s.aes, dynamic) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size

Geometry settings (.qp.s.geom, static) supported:

  • `fill - Fill colour
  • `alpha - Opacity
  • `size - Line size
  • `dashed - Solid or dashed lines

Parameters:

Name Type Description
x symbol x position
settings dict | null settings for the visual (theme/geom/etc)

Returns:

Type Description
table specification tree for a bar chart

Example: Basic vertical rules


 t: ([]x: .st.gen.normal 100000; y: .st.gen.normal 100000);

 .qp.stack (
     .qp.point[t; `x; `y] .qp.s.geom[``alpha!(::; 0x2f)];
     .qp.vline[-2] .qp.s.geom[``fill!(::; `red)];
     .qp.vline[2]  .qp.s.geom[``fill!(::; `red)])

Image

Example: Adding in horizontal rules


 .qp.stack (
     .qp.point[t; `x; `y] .qp.s.geom[``alpha!(::; 0x2f)];
     .qp.hline[0]  .qp.s.geom[``fill!(::; `red)];
     .qp.vline[-2] .qp.s.geom[``fill!(::; `red)];
     .qp.vline[2]  .qp.s.geom[``fill!(::; `red)])

Image