VISUALISE FROM ggsql:penguins
DRAW bar
MAPPING species AS x
Bar
Layers are declared with the
DRAWclause. Read the documentation for this clause for a thorough description of how to use it.
The bar layer is used to create bar plots. You can either specify the height of the bars directly or let the layer calculate it either as the count of records within the same group or as a weighted sum of the records.
Aesthetics
The following aesthetics are recognised by the bar layer.
Required
The bar layer has no required aesthetics
Optional
x: Position on the x-axis. If missing all records will be shown in the same bary: The height of the plot. If missing, it will be calculated by the layercolour: The default colour of each barstroke: The colour of the stroke around each bar. Overridescolourfill: The fill colour of each bar. Overridescolouropacity: The opacity of the bar filllinewidth: The width of the strokelinetype: The type of stroke, i.e. the dashing pattern
Settings
width: The width of the bars as a proportion of the available width
Data transformation
If y has not been mapped the layer will calculate it for you.
Properties
weight: If mapped, the sum of the weights within each group is calculated instead of the count in each group
Calculated statistics
count: The count or, ifweighthave been mapped, sum of weights in each group.proportion: The groupwise proportion, i.e. thecountdivided by the sum ofcountwithin each group
Default remappings
count AS y: By default the barplot will show count as the height of the bars
Examples
Show the number of each species in the data
Use weight to instead show the collective mass of each species
VISUALISE FROM ggsql:penguins
DRAW bar
MAPPING species AS x, body_mass AS weight
Map fill to a discrete value to create a stacked bar chart
VISUALISE FROM ggsql:penguins
DRAW bar
MAPPING species AS x, island AS fill
Map to y if the dataset already contains the value you want to show
SELECT species, MAX(body_mass) AS max_mass FROM ggsql:penguins
GROUP BY species
VISUALISE
DRAW bar
MAPPING species AS x, max_mass AS y