SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
LABEL
title => 'Temperature Distribution',
x => 'Temperature (F)',
y => 'Count'Histogram
statistical
distribution
Distribution of a single numeric variable
Histograms show the distribution of a numeric variable by grouping values into bins and counting occurrences in each bin.
Code
Explanation
VISUALISE Temp AS xspecifies the variable to binDRAW histogramautomatically computes bins and counts- No y mapping is needed - ggsql computes the count automatically
Variations
Custom Bin Count
Control the number of bins with SETTING bins:
SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
SETTING bins => 15
LABEL
title => 'Temperature Distribution (15 bins)',
x => 'Temperature (F)',
y => 'Count'Custom Bin Width
Set explicit bin width instead of count:
SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
SETTING binwidth => 5
LABEL
title => 'Temperature Distribution (5 degree bins)',
x => 'Temperature (F)',
y => 'Count'Density Instead of Count
Use REMAPPING to show density (proportion) instead of count:
SELECT Temp FROM ggsql:airquality
VISUALISE Temp AS x
DRAW histogram
REMAPPING density AS y
LABEL
title => 'Temperature Density',
x => 'Temperature (F)',
y => 'Density'