How to create a labeled scatterplot?

I would like to draw a labeled scatterplot as shown below in Gadfly.

Like this example (Source: http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/images/renda.png )

How can i do this?

The scatter chart is simple:

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) 

The Option option is to use colors, but it’s not so great, because the legend becomes huge (especially in less simple examples than this).

 plot(x=X,y=Y, color=Labels) 

colors

+5
source share
2 answers

While @Oxinabox's answer works, the Gadfly path will use Geom.label , for example

 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) 

Gadfly plot

There are many advantages to this, including clever label placement to avoid overlapping labels, or you can choose from simple rules, such as :centered or below . In addition, he will choose the font size / font from the theme.

+6
source

You can do this with Compose annotations.

Gadfly's documentation of what's here. You may have missed your true strength from the simple example shown.

 Using Compose plot(x=X, y=Y, Guide.annotation(compose(context(), text(X, Y, Labels)))) 

With labels

+1
source

Source: https://habr.com/ru/post/1213943/


All Articles