Guides

Guides

Guide.annotation

using Gadfly, Compose
set_default_plot_size(14cm, 8cm)
plot(sin, 0, 2pi, Guide.annotation(compose(context(),
     Shape.circle([pi/2, 3*pi/2], [1.0, -1.0], [2mm]),
     fill(nothing), stroke("orange"))))
x 0 2 4 6 8 -1.0 -0.5 0.0 0.5 1.0 f(x)

Guide.colorkey

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
Dsleep = dataset("ggplot2", "msleep")[[:Vore,:BrainWt,:BodyWt,:SleepTotal]]
DataFrames.dropmissing!(Dsleep)
Dsleep[:SleepTime] = Dsleep[:SleepTotal] .> 8
plot(Dsleep, x=:BodyWt, y=:BrainWt, Geom.point, color=:SleepTime,
     Guide.colorkey(title="Sleep", labels=[">8","≤8"]),
     Scale.x_log10, Scale.y_log10 )
BodyWt 10-4 10-2 100 102 104 >8 ≤8 Sleep 10-4 10-3 10-2 10-1 100 101 BrainWt
using Gadfly, Compose, RDatasets
set_default_plot_size(21cm, 8cm)
iris = dataset("datasets","iris")
pa = plot(iris, x=:SepalLength, y=:PetalLength, color=:Species, Geom.point,
          Theme(key_position=:inside) )
pb = plot(iris, x=:SepalLength, y=:PetalLength, color=:Species, Geom.point,
          Guide.colorkey(title="Iris", pos=[0.05w,-0.28h]) )
hstack(pa, pb)
SepalLength 4 5 6 7 8 setosa versicolor virginica Iris 0 2 4 6 8 PetalLength SepalLength 4 5 6 7 8 setosa versicolor virginica Species 0 2 4 6 8 PetalLength

Guide.manual_color_key

using Gadfly, DataFrames
set_default_plot_size(14cm, 8cm)
points = DataFrame(index=rand(0:10,30), val=rand(1:10,30))
line = DataFrame(val=rand(1:10,11), index = collect(0:10))
pointLayer = layer(points, x="index", y="val", Geom.point,Theme(default_color="green"))
lineLayer = layer(line, x="index", y="val", Geom.line)
plot(pointLayer, lineLayer,
     Guide.manual_color_key("Legend", ["Points", "Line"], ["green", "deepskyblue"]))
index 0 5 10 Points Line Legend 0.0 2.5 5.0 7.5 10.0 val

Guide.shapekey

using Compose, Gadfly, RDatasets
set_default_plot_size(16cm, 8cm)
Dsleep = dataset("ggplot2", "msleep")
Dsleep = dropmissing!(Dsleep[[:Vore, :Name,:BrainWt,:BodyWt, :SleepTotal]])
Dsleep[:SleepTime] = Dsleep[:SleepTotal] .> 8
plot(Dsleep, x=:BodyWt, y=:BrainWt, Geom.point, color=:Vore, shape=:SleepTime,
    Guide.colorkey(pos=[0.05w, -0.25h]),
    Guide.shapekey(title="Sleep (hrs)", labels=[">8","≤8"], pos=[0.18w,-0.315h]),
    Scale.x_log10, Scale.y_log10,
    Theme(point_size=2mm, key_swatch_color="slategrey",
            point_shapes=[Shape.utriangle, Shape.dtriangle]) )
BodyWt 10-4 10-2 100 102 104 >8 ≤8 Sleep (hrs) omni herbi carni insecti Vore 10-4 10-3 10-2 10-1 100 101 BrainWt

Guide.title

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("ggplot2", "diamonds"), x="Price", Geom.histogram,
     Guide.title("Diamond Price Distribution"))
Price 0 5.0×10³ 1.0×10⁴ 1.5×10⁴ 2.0×10⁴ 0 1×10³ 2×10³ 3×10³ 4×10³ Diamond Price Distribution

Guide.xlabel, Guide.ylabel

using Gadfly
set_default_plot_size(21cm, 8cm)
p1 = plot(cos, 0, 2π, Guide.xlabel("Angle"));
p2 = plot(cos, 0, 2π, Guide.xlabel("Angle", orientation=:vertical));
p3 = plot(cos, 0, 2π, Guide.xlabel(nothing));
hstack(p1,p2,p3)
0 2 4 6 8 -1.0 -0.5 0.0 0.5 1.0 f(x) Angle 0 2 4 6 8 -1.0 -0.5 0.0 0.5 1.0 f(x) Angle 0 2 4 6 8 -1.0 -0.5 0.0 0.5 1.0 f(x)

Guide.xrug, Guide.yrug

using Gadfly
set_default_plot_size(14cm, 8cm)
plot(x=rand(20), y=rand(20), Guide.xrug)
x 0.0 0.5 1.0 0.00 0.25 0.50 0.75 1.00 y

Guide.xticks, Guide.yticks

using Gadfly
set_default_plot_size(21cm, 8cm)
ticks = [0.1, 0.3, 0.5]
p1 = plot(x=rand(10), y=rand(10), Geom.line, Guide.xticks(ticks=ticks))
p2 = plot(x=rand(10), y=rand(10), Geom.line, Guide.xticks(ticks=ticks, label=false))
p3 = plot(x=rand(10), y=rand(10), Geom.line,
          Guide.xticks(ticks=ticks, orientation=:vertical))
hstack(p1,p2,p3)
x 0.1 0.3 0.5 0.0 0.2 0.4 0.6 0.8 y x 0.0 0.5 1.0 y x 0.1 0.3 0.5 0.00 0.25 0.50 0.75 1.00 y
using Gadfly
set_default_plot_size(14cm, 8cm)
plot(x=rand(1:10, 10), y=rand(1:10, 10), Geom.line, Guide.xticks(ticks=[1:9;]))
x 1 2 3 4 5 6 7 8 9 0.0 2.5 5.0 7.5 10.0 y