Label points

Source code notebook

using InMemoryDatasets, StatisticalGraphics, DLMReader, Chain

Scatter automatically put labels of data points around them when a column is passed as labelresponse.

In the following example we use the country name to label data points. Scatter uses clever algorithms to avoid any overlaps between labels and points.

nations = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
                                 "..", "docs", "assets", "nations.csv"),
                                 emptycolname=true, quotechar='"')
@chain nations begin
    filter(:year, by = ==(2010))
    sgplot(Scatter(x=:gdpPercap, y=:lifeExp, group=:region,
                                 labelresponse=:country))
end

Users can control the appearance of labels by passing suitable keyword arguments. However, if users desire to match the color of labels and the points, they can pass labelcolor=:group or labelcolor=:colorresponse accordingly.

@chain nations begin
    filter(:year, by = ==(2010))
    sgplot(Scatter(x=:gdpPercap, y=:lifeExp, group=:region,
                                 labelresponse=:country, labelsize=8,
                                 labelcolor=:group))
end

This page was generated using DemoCards.jl and Literate.jl.