3
votes

I have two layers that I would like to plot as Geom.point. From the Gadfly documentation, I believe this should be possible, though the example only covers the case where the layer Geom types are different. However, when I attempt this (Julia 0.3.0-prerelease+2584, Gadfly v0.2.8) it throws an error:

x = [83, 71, 79, 71, 73, 66, 78, 70, 69, 84, 59, 66, 73]
y = [59, 47, 33, 68, 56, 61, 51, 45, 50, 44, 60, 62, 50]
ox = 74
oy = 49

plot(layer(x=x, y=y, Geom.point),
layer(x=ox, y=oy, Geom.point))

# BoundsError()
#  in eval_plot_mapping at /Users/peter/.julia/v0.3/Gadfly/src/Gadfly.jl:317
#  in render at /Users/peter/.julia/v0.3/Gadfly/src/Gadfly.jl:448
#  in writemime at /Users/peter/.julia/v0.3/Gadfly/src/Gadfly.jl:753
#  in sprint at io.jl:460
#  in display_dict at /Users/peter/.julia/v0.3/IJulia/src/execute_request.jl:35

Ultimately, I'd also like to manually specify an aesthetic for the layer (e.g. Geom.point(color="red").

Am I missing something about the slang of graphics, or are two same type Geom layers not supported in the slang? If they are, then how can I go about setting different aesthetics for each layer?

1
What is zeros, ones, ozeros and oones? - Mr Alpha
Oh jeez, I tried to make a reproducible version of something I was working on by adding some sample data, but then forgot to rename my variables! Thanks for catching that! Fixed now. - Peter
I think Gadfly expects x and y to be vectors, so plotting scalars won't work. - Mr Alpha
Right you are. ox and oy defined as [74] and [49] works like a charm. This also gives me the hint that I can do something like plot(layer(x=x, y=y, color=["foo"], Geom.point), layer(x=ox, y=oy, color=["bar"], Geom.point)) to get my colors. If you submit an answer, I'll gladly accept it! - Peter

1 Answers

4
votes

Gadfly expects x and y to be vectors, so plotting scalars won't work.

Besides providing a separate string for each layer to get different colors you can also use Theme to change the color manually, for example: Theme(default_color=color("red"))