Distributions

Loading Ebi…
type WeatherDay = {
    date: String, precipitation: Number, temp_max: Number,
    temp_min: Number, wind: Number, weather: String
}
let url = "https://raw.githubusercontent.com/vega/vega/main/docs/data/seattle-weather.csv"
let days = read<List<WeatherDay>>(url)
let highs = days.map(fn (day: WeatherDay): Number { return day.temp_max })
let bins = reflect(18)
let bandwidth = reflect(2)
let xs = LinearScale(domain=[-5, 40], range=[-180pt, 180pt])
let ys = LinearScale(domain=[0, 0.08], range=[80pt, -80pt])
let bars = <Histogram values={highs} bins={bins} normalization="density" x_scale={xs} y_scale={ys} fill="blue4"/>
let estimate = <DensityPlot values={highs} bandwidth={bandwidth} x_scale={xs} y_scale={ys} fill="orange3" shade={false}/>
let ax = NumberPlane(x_range=[-5, 40, 5], y_range=[0, 0.08, 0.02], x_length=360pt, y_length=160pt)
<Plot axes={ax} edge_axes={true} font_size={10pt}>
    {bars}
    {estimate}
</Plot>
<Text text="Density" position={[-180pt, -98pt]} font_size={12pt}/>
<Text text="Daily high (°C)" position={[0pt, 104pt]} font_size={12pt}/>
estimate.create(duration=1s)
wait(500ms)
estimate.uncreate(duration=1s)

The bars group Seattle’s 1,461 daily high temperatures from 2012 through 2015. Adjust Bins to change the groups or Bandwidth to change how much the orange density curve smooths the observations. NOAA data via Vega Datasets

Choose a plot

UseTo show
Scatter, LinePlotIndividual points or a connected series.
AreaPlot, BandPlotThe area below a series or between its low and high values.
BoxPlot, BoxSummary(values)A distribution summarized by quartiles.
Histogram, DensityPlot, NormalCurve, ECDFPlotBins, a smoothed estimate, a normal model, or cumulative observations.
Axis, Grid, LegendTicks, grid lines, and labels.

LinearScale maps a data domain to a coordinate range. Use DataRange(values) to get a domain from the data. Pass lists directly, use a typed SQL query, or convert a DataFrame with df.select(["x", "y"]).to_list().