scatter

scatter(
    data,
    x,
    y,
    year=None,
    *,
    color=None,
    size=None,
    fit='ols',
    log_x=False,
    log_y=False,
    title=None,
    ref=None,
)

Two variables against each other in one year, one point per unit.

Parameters

Name Type Description Default
data A dataset id, or a panel with geo_id (and year), e.g. from load required
x str The numeric columns on the horizontal and the vertical axis required
y str The numeric columns on the horizontal and the vertical axis required
year The year to plot (default: the last with data for x), or "all" to pool every year (one point per unit and year) None
color str | None Colour the points by a column (categories, or a numeric variable on a continuous scale) or by a coarser scale of the units, whose names are added None
size str | None A non-negative numeric column that sets the area of the points None
fit str | None The line drawn: "ols" (least squares, with its slope, R² and the correlation written on the figure), "lowess" (a local smooth) or None 'ols'
log_x bool Logarithmic axes; the line and the numbers then use natural logarithms, and units with a value of zero or less are left out False
log_y bool Logarithmic axes; the line and the numbers then use natural logarithms, and units with a value of zero or less are left out False
title str | None The figure title None

Returns

Name Type Description
ScatterResult A result with .df (the units plotted: geo_id, name and the columns used), .fig (the unit names show on hover), .slope, .intercept, .r2 and .p_value (of the least-squares line of y on x, whichever fit is drawn), .corr (Pearson), .n (units), .year, .notes and .interpret().

Example

!pip install -q geo4bolivia
import geo4bolivia as geo

res = geo.scatter("sdg", "urbanization", "index_sdg",
                  color="department", size="population")
print(res.interpret())
res.fig

Across 343 units in 2024, Sustainable Development Index, IDS (0-100) and Urbanization rate (% of population) are positively correlated (r = 0.56, a moderate association): units with higher Urbanization rate (% of population) tend to have higher Sustainable Development Index, IDS (0-100).

The least-squares line has a slope of 0.094: one more unit of Urbanization rate (% of population) goes with 0.094 higher Sustainable Development Index, IDS (0-100), on average. The line accounts for 31% of the variation in Sustainable Development Index, IDS (0-100) across units (R² = 0.31); the slope is statistically significant at the 1% level, by a test that treats the units as independent of each other.

These are associations, not causal effects. A causal reading needs a research design.