I would like to draw a labelled scatterplot, like shown below, in Gadfly.
(Source: http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/images/renda.png)
How can I do this?
The scatter plot is easy:
using Gadfly
X = [1, 2, 2, 3, 3, 3, 4]
Y = [4, 4, 7, 7, 9, 1, 8]
Labels = ["bill", "susan", "megan", "eric", "fran", "alex", "fred"]
plot(x=X, y=Y)
On Option is to use colours, but that isn't so great, cos the legend becomes huge (particularly in less trivial examples than this).
plot(x=X,y=Y, color=Labels)
While @Oxinabox's answer works, the Gadfly way would be to use Geom.label
, e.g.
using Gadfly
X = [1, 2, 2, 3, 3, 3, 4]
Y = [4, 4, 7, 7, 9, 1, 8]
Labels = ["bill", "susan", "megan", "eric", "fran", "alex", "fred"]
plot(x=X, y=Y, label=Labels, Geom.point, Geom.label)
There are a lot of benefits to this, including smart label placement to avoid label overlap, or you can pick from some easy-to-use rules like :centered
or below
. Plus it'll pick up font/font size from the theme.