GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.9k stars 251 forks source link

How to get labels on the points? #972

Closed jkleiser closed 7 years ago

jkleiser commented 7 years ago

In the second Brain-Body plot shown at http://gadflyjl.org/stable/tutorial.html, there are labels (Owl monkey, Galago, ...) shown on each point. How is this achieved? For me it would be much better to have labels on the points, instead of having a legend group on the right mapping colors to labels.

Mattriks commented 7 years ago

Did you try running the example code:

using RDatasets, DataFrames, Gadfly
mammals = dataset("MASS", "mammals")

p=plot(mammals, x=:Body, y=:Brain, label=:Mammal,
         Geom.point, Geom.label, Scale.x_log10, Scale.y_log10)

See also the documentation on Geoms: note Geom.label and the aesthetic label=:Mammal

Timmmm commented 5 years ago

The examples are really not very helpful because it means I have to learn how to make a dataset. It would be better if they show an example not using a dataset (is that even possible? you can't tell from the examples) or show you how to actually make a dataset from data.

Timmmm commented 5 years ago

Future people trying to find the documentation in a sea of outdated links... It's something like this:

One-time installation:

using Pkg;
Pkg.add("Gadfly");
Pkg.add("DataFrames");

In your script:

using Gadfly;
using DataFrames;

df = DataFrame(age = [1, 2, 3], weight = [3, 4, 5], names = ["dave", "john", "mary"]);
plot(df, x="age", y="weight", label="names", Geom.point, Geom.label);

Check the date because I'm sure this will change in a few months...

bjarthur commented 5 years ago

docs on how to use arrays: http://gadflyjl.org/latest/tutorial/#Arrays-1

happy to fix links if you tell me which ones are outdated.

Timmmm commented 5 years ago

That's weird, I could have sworn I tried something like that and it didn't work, but I just tried again and it does. :-S

Btw off-topic but I think it would also be worth explaining the :Foo syntax on that page, because both of these work and it's not clear what the difference is:

df = DataFrame(age = [1, 2, 3], weight = [3, 4, 5], names = ["dave", "john", "mary"]);
plot(df, x="age", y="weight", label="names", Geom.point, Geom.label)
plot(df, x=:age, y=:weight, label=:names, Geom.point, Geom.label)