VISUALISE bill_len AS x, bill_dep AS y FROM ggsql:penguins
DRAW point
LABEL
title => 'Penguin Bill Dimensions',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'Scatter plot
A scatter plot displays the relationship between two numeric variables by mapping them to x and y positions. This is one of the most fundamental visualization types for exploring correlations and patterns.
Code
Explanation
VISUALISE ... FROM ggsql:penguinsloads the built-in penguins datasetbill_len AS x, bill_dep AS ymaps bill length to the x-axis and bill depth to the y-axisDRAW pointcreates a scatter plot using pointsLABELadds descriptive axis labels and a title
Variations
With color by species
We’re adding species AS color to the mapping to colour the points by species.
VISUALISE bill_len AS x, bill_dep AS y, species AS color FROM ggsql:penguins
DRAW point
LABEL
title => 'Penguin Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'The color palette can be changed by detailing the SCALE color clause.
VISUALISE bill_len AS x, bill_dep AS y, species AS color FROM ggsql:penguins
DRAW point
SCALE color TO ('DeepSkyBlue', 'Fuchsia', 'Lime')
LABEL
title => 'Penguin Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'Encoding even more data using shape
We can also encode a second layer of information by displaying island AS shape.
VISUALISE
bill_len AS x,
bill_dep AS y,
species AS color,
island AS shape
FROM ggsql:penguins
DRAW point
LABEL
title => 'Penguin Bill Dimensions by Species',
x => 'Bill Length (mm)',
y => 'Bill Depth (mm)'Highlighting groups
Using the layer’s FILTER clause we can split the data across layers. Using layer level MAPPING ensures we apply species AS color only to one layer and not the other. The SETTING is used here to directly set a property without mapping data.
VISUALISE
bill_len AS x,
bill_dep AS y
FROM ggsql:penguins
DRAW point
MAPPING species AS color
FILTER island == 'Biscoe'
DRAW point
SETTING color => 'grey'
FILTER island != 'Biscoe'