Geometries

Geometries

Geom.abline

using Gadfly, RDatasets, Compose
set_default_plot_size(14cm, 8cm)
plot(dataset("ggplot2", "mpg"),
     x="Cty", y="Hwy", label="Model", Geom.point, Geom.label,
     intercept=[0], slope=[1], Geom.abline(color="red", style=:dash),
     Guide.annotation(compose(context(), text(6,4, "y=x", hleft, vtop), fill("red"))))
Cty 0 10 20 30 40 a4 a4 a4 a4 a4 a4 a4 a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a6 quattro a6 quattro a6 quattro c1500 suburban 2wd c1500 suburban 2wd c1500 suburban 2wd c1500 suburban 2wd c1500 suburban 2wd corvette corvette corvette corvette corvette k1500 tahoe 4wd k1500 tahoe 4wd k1500 tahoe 4wd k1500 tahoe 4wd malibu malibu malibu malibu malibu caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd durango 4wd durango 4wd durango 4wd durango 4wd durango 4wd durango 4wd durango 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd expedition 2wd expedition 2wd expedition 2wd explorer 4wd explorer 4wd explorer 4wd explorer 4wd explorer 4wd explorer 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd mustang mustang mustang mustang mustang mustang mustang mustang mustang civic civic civic civic civic civic civic civic civic sonata sonata sonata sonata sonata sonata sonata tiburon tiburon tiburon tiburon tiburon tiburon tiburon grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd range rover range rover range rover range rover navigator 2wd navigator 2wd navigator 2wd mountaineer 4wd mountaineer 4wd mountaineer 4wd mountaineer 4wd altima altima altima altima altima altima maxima maxima maxima pathfinder 4wd pathfinder 4wd pathfinder 4wd pathfinder 4wd grand prix grand prix grand prix grand prix grand prix forester awd forester awd forester awd forester awd forester awd forester awd impreza awd impreza awd impreza awd impreza awd impreza awd impreza awd impreza awd impreza awd 4runner 4wd 4runner 4wd 4runner 4wd 4runner 4wd 4runner 4wd 4runner 4wd camry camry camry camry camry camry camry camry solara camry solara camry solara camry solara camry solara camry solara camry solara corolla corolla corolla corolla corolla land cruiser wagon 4wd land cruiser wagon 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd gti gti gti gti gti jetta jetta jetta jetta jetta jetta jetta jetta jetta new beetle new beetle new beetle new beetle new beetle new beetle passat passat passat passat passat passat passat y=x 0 10 20 30 40 50 Hwy

Geom.bar

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("HistData", "ChestSizes"), x="Chest", y="Count", Geom.bar)
Chest 30 35 40 45 50 0 500 1000 1500 Count
using Gadfly, RDatasets, DataFrames
set_default_plot_size(21cm, 8cm)

D = by(dataset("datasets","HairEyeColor"), [:Eye,:Sex], d->sum(d[:Freq]))
p1 = plot(D, color="Eye", y="x1", x="Sex", Geom.bar(position=:dodge),
          Guide.ylabel("Freq"));

rename!(D, :x1 => :Frequency)
palette = ["brown","blue","tan","green"]  # Is there a hazel color?

p2a = plot(D, x=:Sex, y=:Frequency, color=:Eye, Geom.bar(position=:stack),
           Scale.color_discrete_manual(palette...));
p2b = plot(D, x=:Sex, y=:Frequency, color=:Eye, Geom.bar(position=:stack),
           Scale.color_discrete_manual(palette[4:-1:1]..., order=[4,3,2,1]));

hstack(p1, p2a, p2b)
Sex Male Female Green Hazel Blue Brown Eye 0 100 200 300 400 Frequency Sex Male Female Brown Blue Hazel Green Eye 0 100 200 300 400 Frequency Sex Male Female Brown Blue Hazel Green Eye 0 50 100 150 Freq

See Scale.color_discrete_manual for more information.

Geom.beeswarm

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("lattice", "singer"), x="VoicePart", y="Height", Geom.beeswarm)
VoicePart Soprano 1 Soprano 2 Alto 1 Alto 2 Tenor 1 Tenor 2 Bass 1 Bass 2 60 65 70 75 80 Height

Geom.boxplot

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("lattice", "singer"), x="VoicePart", y="Height", Geom.boxplot)
VoicePart Soprano 1 Soprano 2 Alto 1 Alto 2 Tenor 1 Tenor 2 Bass 1 Bass 2 60 65 70 75 80 Height

Geom.contour

using Gadfly
set_default_plot_size(14cm, 8cm)
plot(z=(x,y) -> x*exp(-(x-round(Int, x))^2-y^2),
     xmin=[-8], xmax=[8], ymin=[-2], ymax=[2], Geom.contour)
xmin -10 -5 0 5 10 5 10 -10 -5 0 Color -2 -1 0 1 2 ymin
using Gadfly, RDatasets
set_default_plot_size(21cm, 16cm)
volcano = Matrix{Float64}(dataset("datasets", "volcano"))
p1 = plot(z=volcano, Geom.contour)
p2 = plot(z=volcano, Geom.contour(levels=[110.0, 150.0, 180.0, 190.0]))
p3 = plot(z=volcano, x=collect(0.0:10:860.0), y=collect(0.0:10:600.0),
          Geom.contour(levels=2))
Mv = volcano[1:4:end, 1:4:end]
Dv = vcat([DataFrame(x=[1:size(Mv,1);], y=j, z=Mv[:,j]) for j in 1:size(Mv,2)]...)
p4 = plot(Dv, x=:x, y=:y, z=:z, color=:z,
          Coord.cartesian(xmin=1, xmax=22, ymin=1, ymax=16),
          Geom.point, Geom.contour(levels=10),
          style(line_width=0.5mm, point_size=0.2mm) )
gridstack([p1 p2; p3 p4])
x 5 10 15 20 200 100 50 150 z 5 10 15 y x 0 200 400 600 800 130 160 140 150 170 120 Color 0 100 200 300 400 500 600 y 0 25 50 75 100 140 120 170 190 180 110 130 150 160 Color 0 20 40 60 80 0 25 50 75 100 200 100 150 Color 0 20 40 60 80

Geom.density

using Gadfly, RDatasets, Distributions
set_default_plot_size(21cm, 8cm)
p1 = plot(dataset("ggplot2", "diamonds"), x="Price", Geom.density)
p2 = plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut", Geom.density)
hstack(p1,p2)
Price -1×10⁴ 0 1×10⁴ 2×10⁴ 3×10⁴ Ideal Premium Good Very Good Fair Cut 0.0000 0.0001 0.0002 0.0003 0.0004 0.0005 Price -1×10⁴ 0 1×10⁴ 2×10⁴ 3×10⁴ 0.0000 0.0001 0.0002 0.0003 0.0004
using Gadfly, RDatasets, Distributions
set_default_plot_size(14cm, 8cm)
dist = MixtureModel(Normal, [(0.5, 0.2), (1, 0.1)])
xs = rand(dist, 10^5)
plot(layer(x=xs, Geom.density, Theme(default_color="orange")),
     layer(x=xs, Geom.density(bandwidth=0.0003), Theme(default_color="green")),
     layer(x=xs, Geom.density(bandwidth=0.25), Theme(default_color="purple")),
     Guide.manual_color_key("bandwidth", ["auto", "bw=0.0003", "bw=0.25"],
                            ["orange", "green", "purple"]))
x -2 -1 0 1 2 3 auto bw=0.0003 bw=0.25 bandwidth 0.0 0.5 1.0 1.5 2.0 2.5

Geom.density2d

using Gadfly, Distributions
set_default_plot_size(14cm, 8cm)
plot(x=rand(Rayleigh(2),1000), y=rand(Rayleigh(2),1000),
     Geom.density2d(levels = x->maximum(x)*0.5.^collect(1:2:8)), Geom.point,
     Theme(key_position=:none),
     Scale.color_continuous(colormap=x->colorant"red"))
x -5 0 5 10 -2 0 2 4 6 8 y

Geom.ellipse

using RDatasets, Gadfly
set_default_plot_size(21cm, 8cm)
D = dataset("datasets","faithful")
D[:g] = D[:Eruptions].>3.0
coord = Coord.cartesian(ymin=35, ymax=100)
pa = plot(D, coord,
          x=:Eruptions, y=:Waiting, group=:g,
          Geom.point, Geom.ellipse)
pb = plot(D, coord,
          x=:Eruptions, y=:Waiting, color=:g,
          Geom.point, Geom.ellipse,
          layer(Geom.ellipse(levels=[0.99]), style(line_style=[:dot])),
          style(key_position=:none), Guide.ylabel(nothing))
hstack(pa,pb)
Eruptions 0 1 2 3 4 5 6 50 100 Eruptions 0 1 2 3 4 5 6 50 100 Waiting

Geom.errorbar

using Gadfly, RDatasets, Distributions
set_default_plot_size(14cm, 8cm)
srand(1234)
sds = [1, 1/2, 1/4, 1/8, 1/16, 1/32]
n = 10
ys = [mean(rand(Normal(0, sd), n)) for sd in sds]
ymins = ys .- (1.96 * sds / sqrt(n))
ymaxs = ys .+ (1.96 * sds / sqrt(n))
plot(x=1:length(sds), y=ys, ymin=ymins, ymax=ymaxs,
     Geom.point, Geom.errorbar)
x 0 1 2 3 4 5 6 -0.5 0.0 0.5 1.0 y

Geom.hair

using Gadfly
set_default_plot_size(21cm, 8cm)
x= 1:10
s = [-1,-1,1,1,-1,-1,1,1,-1,-1]
pa = plot(x=x, y=x.^2, Geom.hair, Geom.point)
pb = plot(x=s.*(x.^2), y=x, color=string.(s),
          Geom.hair(orientation=:horizontal), Geom.point, Theme(key_position=:none))
hstack(pa, pb)
x -100 -50 0 50 100 0.0 2.5 5.0 7.5 10.0 y x 0.0 2.5 5.0 7.5 10.0 0 50 100 y

Geom.hexbin

using Gadfly, Distributions
set_default_plot_size(21cm, 8cm)
X = rand(MultivariateNormal([0.0, 0.0], [1.0 0.5; 0.5 1.0]), 10000);
p1 = plot(x=X[1,:], y=X[2,:], Geom.hexbin)
p2 = plot(x=X[1,:], y=X[2,:], Geom.hexbin(xbincount=100, ybincount=100))
hstack(p1,p2)
x -5 0 5 20 10 40 1 30 Count -4 -2 0 2 4 y x -5 0 5 10 5 15 1 Count -4 -2 0 2 4 y

Geom.histogram

using Gadfly, RDatasets
set_default_plot_size(21cm, 16cm)
p1 = plot(dataset("ggplot2", "diamonds"), x="Price", Geom.histogram)
p2 = plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut", Geom.histogram)
p3 = plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut",
          Geom.histogram(bincount=30))
p4 = plot(dataset("ggplot2", "diamonds"), x="Price", color="Cut",
          Geom.histogram(bincount=30, density=true))
gridstack([p1 p2; p3 p4])
Price 0 5.0×10³ 1.0×10⁴ 1.5×10⁴ 2.0×10⁴ Ideal Premium Good Very Good Fair Cut 0.0000 0.0005 0.0010 0.0015 0.0020 Price 0 5.0×10³ 1.0×10⁴ 1.5×10⁴ 2.0×10⁴ Ideal Premium Good Very Good Fair Cut 0 5.0×10³ 1.0×10⁴ 1.5×10⁴ Price 0 5.0×10³ 1.0×10⁴ 1.5×10⁴ 2.0×10⁴ Ideal Premium Good Very Good Fair Cut 0 1×10³ 2×10³ 3×10³ 4×10³ Price 0 5.0×10³ 1.0×10⁴ 1.5×10⁴ 2.0×10⁴ 0 1×10³ 2×10³ 3×10³ 4×10³

Geom.histogram2d

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
p1 = plot(dataset("car", "Womenlf"), x="HIncome", y="Region", Geom.histogram2d)
p2 = plot(dataset("car", "UN"), x="GDP", y="InfantMortality",
          Scale.x_log10, Scale.y_log10, Geom.histogram2d)
p3 = plot(dataset("car", "UN"), x="GDP", y="InfantMortality",
          Scale.x_log10, Scale.y_log10, Geom.histogram2d(xbincount=30, ybincount=30))
hstack(p1,p2,p3)
GDP 100 101 102 103 104 105 4 5 1 2 3 Count 100.0 100.5 101.0 101.5 102.0 102.5 InfantMortality GDP 100 101 102 103 104 105 2.5 3.0 1.0 1.5 2.0 Count 100.0 100.5 101.0 101.5 102.0 102.5 InfantMortality HIncome 0 10 20 30 40 50 10 5 15 1 Count Ontario Prairie Atlantic BC Quebec Region

Geom.hline, Geom.vline

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
p1 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth",
          xintercept=[5.0, 7.0], Geom.point, Geom.vline(style=[:solid,[1mm,1mm]]))
p2 = plot(dataset("datasets", "iris"), x="SepalLength", y="SepalWidth",
          yintercept=[2.5, 4.0], Geom.point,
          Geom.hline(color=["orange","red"], size=[2mm,3mm]))
hstack(p1,p2)
SepalLength 4 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth SepalLength 4 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth

Geom.label

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("ggplot2", "mpg"), x="Cty", y="Hwy", label="Model",
     Geom.point, Geom.label)
Cty 0 10 20 30 40 a4 a4 a4 a4 a4 a4 a4 a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a4 quattro a6 quattro a6 quattro a6 quattro c1500 suburban 2wd c1500 suburban 2wd c1500 suburban 2wd c1500 suburban 2wd c1500 suburban 2wd corvette corvette corvette corvette corvette k1500 tahoe 4wd k1500 tahoe 4wd k1500 tahoe 4wd k1500 tahoe 4wd malibu malibu malibu malibu malibu caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd caravan 2wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd dakota pickup 4wd durango 4wd durango 4wd durango 4wd durango 4wd durango 4wd durango 4wd durango 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd ram 1500 pickup 4wd expedition 2wd expedition 2wd expedition 2wd explorer 4wd explorer 4wd explorer 4wd explorer 4wd explorer 4wd explorer 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd f150 pickup 4wd mustang mustang mustang mustang mustang mustang mustang mustang mustang civic civic civic civic civic civic civic civic civic sonata sonata sonata sonata sonata sonata sonata tiburon tiburon tiburon tiburon tiburon tiburon tiburon grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd grand cherokee 4wd range rover range rover range rover range rover navigator 2wd navigator 2wd navigator 2wd mountaineer 4wd mountaineer 4wd mountaineer 4wd mountaineer 4wd altima altima altima altima altima altima maxima maxima maxima pathfinder 4wd pathfinder 4wd pathfinder 4wd pathfinder 4wd grand prix grand prix grand prix grand prix grand prix forester awd forester awd forester awd forester awd forester awd forester awd impreza awd impreza awd impreza awd impreza awd impreza awd impreza awd impreza awd impreza awd 4runner 4wd 4runner 4wd 4runner 4wd 4runner 4wd 4runner 4wd 4runner 4wd camry camry camry camry camry camry camry camry solara camry solara camry solara camry solara camry solara camry solara camry solara corolla corolla corolla corolla corolla land cruiser wagon 4wd land cruiser wagon 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd toyota tacoma 4wd gti gti gti gti gti jetta jetta jetta jetta jetta jetta jetta jetta jetta new beetle new beetle new beetle new beetle new beetle new beetle passat passat passat passat passat passat passat 0 10 20 30 40 50 Hwy
using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
p1 = plot(dataset("MASS", "mammals"), x="Body", y="Brain", label=1,
     Scale.x_log10, Scale.y_log10, Geom.point, Geom.label)
p2 = plot(dataset("MASS", "mammals"), x="Body", y="Brain", label=1,
     Scale.x_log10, Scale.y_log10, Geom.label(position=:centered))
hstack(p1,p2)
Body 10-4 10-2 100 102 104 Arctic fox Owl monkey Mountain beaver Cow Grey wolf Goat Roe deer Guinea pig Verbet Chinchilla Ground squirrel Arctic ground squirrel African giant pouched rat Lesser short-tailed shrew Star-nosed mole Nine-banded armadillo Tree hyrax N.A. opossum Asian elephant Big brown bat Donkey Horse European hedgehog Patas monkey Cat Galago Genet Giraffe Gorilla Grey seal Rock hyrax-a Human African elephant Water opossum Rhesus monkey Kangaroo Yellow-bellied marmot Golden hamster Mouse Little brown bat Slow loris Okapi Rabbit Sheep Jaguar Chimpanzee Baboon Desert hedgehog Giant armadillo Rock hyrax-b Raccoon Rat E. American mole Mole rat Musk shrew Pig Echidna Brazilian tapir Tenrec Phalanger Tree shrew Red fox 10-1 100 101 102 103 104 Brain Body 10-4 10-2 100 102 104 Arctic fox Owl monkey Mountain beaver Cow Grey wolf Goat Roe deer Guinea pig Verbet Chinchilla Ground squirrel Arctic ground squirrel African giant pouched rat Lesser short-tailed shrew Star-nosed mole Nine-banded armadillo Tree hyrax N.A. opossum Asian elephant Big brown bat Donkey Horse European hedgehog Patas monkey Cat Galago Genet Giraffe Gorilla Grey seal Rock hyrax-a Human African elephant Water opossum Rhesus monkey Kangaroo Yellow-bellied marmot Golden hamster Mouse Little brown bat Slow loris Okapi Rabbit Sheep Jaguar Chimpanzee Baboon Desert hedgehog Giant armadillo Rock hyrax-b Raccoon Rat E. American mole Mole rat Musk shrew Pig Echidna Brazilian tapir Tenrec Phalanger Tree shrew Red fox 10-1 100 101 102 103 104 Brain

Geom.line

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
p1 = plot(dataset("lattice", "melanoma"), x="Year", y="Incidence", Geom.line)
p2 = plot(dataset("Zelig", "approval"), x="Month",  y="Approve", color="Year",
          Geom.line)
hstack(p1,p2)
Month 0 5 10 15 2002 2005 2003 2004 2006 2001 Year 30 40 50 60 70 80 90 Approve Year 1930 1940 1950 1960 1970 1980 0 1 2 3 4 5 Incidence

Geom.path

using Gadfly
set_default_plot_size(21cm, 8cm)

n = 500
srand(1234)
xjumps = rand(n)-.5
yjumps = rand(n)-.5
p1 = plot(x=cumsum(xjumps),y=cumsum(yjumps),Geom.path)

t = 0:0.2:8pi
p2 = plot(x=t.*cos(t), y=t.*sin(t), Geom.path)

hstack(p1,p2)
x -30 -20 -10 0 10 20 30 -30 -20 -10 0 10 20 30 y x -15 -10 -5 0 5 -5 0 5 10 y

Geom.point

using Gadfly, RDatasets
set_default_plot_size(21cm, 12cm)
D = dataset("datasets", "iris")
p1 = plot(D, x="SepalLength", y="SepalWidth", Geom.point);
p2 = plot(D, x="SepalLength", y="SepalWidth", color="PetalLength", Geom.point);
p3 = plot(D, x="SepalLength", y="SepalWidth", color="Species", Geom.point);
p4 = plot(D, x="SepalLength", y="SepalWidth", color="Species", shape="Species",
          Geom.point);
gridstack([p1 p2; p3 p4])
SepalLength 4 5 6 7 8 setosa versicolor virginica Species 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth SepalLength 4 5 6 7 8 setosa versicolor virginica Species 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth SepalLength 4 5 6 7 8 2 8 4 6 1 PetalLength 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth SepalLength 4 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth
using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("lattice", "singer"), x="VoicePart", y="Height", Geom.point)
VoicePart Soprano 1 Soprano 2 Alto 1 Alto 2 Tenor 1 Tenor 2 Bass 1 Bass 2 60 65 70 75 80 Height
using Gadfly, Distributions
set_default_plot_size(14cm, 8cm)
rdata = rand(MvNormal([0,0.],[1 0;0 1.]),100)
bdata = rand(MvNormal([1,0.],[1 0;0 1.]),100)
plot(layer(x=rdata[1,:], y=rdata[2,:], color=[colorant"red"], Geom.point),
     layer(x=bdata[1,:], y=bdata[2,:], color=[colorant"blue"], Geom.point))
x -4 -2 0 2 4 -4 -2 0 2 4 y

Geom.polygon

using Gadfly
set_default_plot_size(14cm, 8cm)
plot(x=[0, 1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 0, 4, 5, 5, 4],
     y=[0, 0, 1, 1, 0, 0, 3, 3, 2, 2, 3, 3, 0, 0, 3, 3],
     group=["H", "H", "H", "H", "H", "H", "H", "H",
            "H", "H", "H", "H", "I", "I", "I", "I"],
     Geom.polygon(preserve_order=true, fill=true))
x 0 1 2 3 4 5 0 1 2 3 y

Geom.rect, Geom.rectbin

using Gadfly, Colors, DataFrames, RDatasets
set_default_plot_size(21cm, 8cm)
theme1 = Theme(default_color=RGBA(0, 0.75, 1.0, 0.5))
D = DataFrame(x=[0.5,1], y=[0.5,1], x1=[0,0.5], y1=[0,0.5], x2=[1,1.5], y2=[1,1.5])
pa = plot(D, x=:x, y=:y, Geom.rectbin, theme1)
pb = plot(D, xmin=:x1, ymin=:y1, xmax=:x2, ymax=:y2, Geom.rect, theme1)
hstack(pa, pb)
x1 0.0 0.5 1.0 1.5 0.0 0.5 1.0 1.5 y1 x 0.0 0.5 1.0 1.5 0.0 0.5 1.0 1.5 y
using Gadfly, DataFrames, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin)
Year 1960 1970 1980 1990 2000 10 15 -5 0 5 GDP United States Canada United Kingdom Netherlands Belgium France West Germany Austria Italy Finland Sweden Norway Denmark Japan Country

Geom.ribbon

using Gadfly, Colors, DataFrames, Distributions
set_default_plot_size(21cm, 8cm)
X = [cos.(0:0.1:20) sin.(0:0.1:20)]
x = -4:0.1:4
Da = [DataFrame(x=0:0.1:20, y=X[:,j], ymin=X[:,j].-0.5, ymax=X[:,j].+0.5, f="$f")  for (j,f) in enumerate(["cos","sin"])]
Db = [DataFrame(x=x, ymax=pdf.(Normal(μ),x), ymin=0.0, u="μ=$μ") for μ in [-1,1] ]

# In the line below, 0.4 is the color opacity
p1 = plot(vcat(Da...), x=:x, y=:y, ymin=:ymin, ymax=:ymax, color=:f, Geom.line, Geom.ribbon,
    Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4))
)
p2 = plot(vcat(Db...), x = :x, y=:ymax, ymin = :ymin, ymax = :ymax, color = :u,
    Geom.line, Geom.ribbon, Guide.ylabel("Density"),
    Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.4)),
    Guide.colorkey(title="", pos=[2.5,0.6]), Guide.title("Parametric PDF")
)
hstack(p1,p2)
x -4 -2 0 2 4 μ=-1 μ=1 0.0 0.1 0.2 0.3 0.4 Density Parametric PDF x 0 5 10 15 20 cos sin f -2 -1 0 1 2 y

Geom.smooth

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
x_data = 0.0:0.1:2.0
y_data = x_data.^2 + rand(length(x_data))
p1 = plot(x=x_data, y=y_data, Geom.point, Geom.smooth(method=:loess,smoothing=0.9))
p2 = plot(x=x_data, y=y_data, Geom.point, Geom.smooth(method=:loess,smoothing=0.2))
hstack(p1,p2)
x 0.0 0.5 1.0 1.5 2.0 0 1 2 3 4 5 y x 0.0 0.5 1.0 1.5 2.0 0 1 2 3 4 5 y

Geom.step

using Gadfly
set_default_plot_size(14cm, 8cm)
srand(1234)
plot(x=rand(25), y=rand(25), Geom.step)
x 0.0 0.5 1.0 0.0 0.5 1.0 y

Geom.subplot_grid

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)
plot(dataset("datasets", "OrchardSprays"),
     xgroup="Treatment", x="ColPos", y="RowPos", color="Decrease",
     Geom.subplot_grid(Geom.point))
ColPos by Treatment 150 50 100 1 Decrease A C F G H B E D 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 RowPos
using Gadfly, RDatasets
set_default_plot_size(14cm, 25cm)
plot(dataset("vcd", "Suicide"), xgroup="Sex", ygroup="Method", x="Age", y="Freq",
     Geom.subplot_grid(Geom.bar))
Age by Sex female male 0 50 100 0 50 100 0 500 1000 1500 other 0 500 1000 1500 jump 0 500 1000 1500 knife 0 500 1000 1500 gun 0 500 1000 1500 drown 0 500 1000 1500 hang 0 500 1000 1500 toxicgas 0 500 1000 1500 cookgas 0 500 1000 1500 poison Freq by Method
using Gadfly, RDatasets, DataFrames
set_default_plot_size(14cm, 8cm)
iris = dataset("datasets", "iris")
sp = unique(iris[:Species])
Dhl = DataFrame(yint=[3.0, 4.0, 2.5, 3.5, 2.5, 4.0], Species=repeat(sp, inner=[2]) )
# Try this one too:
# Dhl = DataFrame(yint=[3.0, 4.0, 2.5, 3.5], Species=repeat(sp[1:2], inner=[2]) )
plot(iris, xgroup=:Species, x=:SepalLength, y=:SepalWidth,
    Geom.subplot_grid(layer(Geom.point),
                      layer(Dhl, xgroup=:Species, yintercept=:yint,
                            Geom.hline(color="red", style=:dot))))
SepalLength by Species virginica versicolor setosa 4 5 6 7 8 4 5 6 7 8 4 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 SepalWidth
using Gadfly, RDatasets, DataFrames
set_default_plot_size(14cm, 8cm)
iris = dataset("datasets", "iris")
sp = unique(iris[:Species])
Dhl = DataFrame(yint=[3.0, 4.0, 2.5, 3.5, 2.5, 4.0], Species=repeat(sp, inner=[2]) )
plot(iris, xgroup=:Species,
     Geom.subplot_grid(layer(x=:SepalLength, y=:SepalWidth, Geom.point),
                       layer(Dhl, xgroup=:Species, yintercept=:yint,
                             Geom.hline(color="red", style=:dot))),
     Guide.xlabel("Xlabel"), Guide.ylabel("Ylabel"))
Xlabel virginica versicolor setosa 4 5 6 7 8 4 5 6 7 8 4 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 Ylabel
using Gadfly, RDatasets, DataFrames
set_default_plot_size(14cm, 12cm)
widedf = DataFrame(x = collect(1:10), var1 = collect(1:10), var2 = collect(1:10).^2)
longdf = stack(widedf, [:var1, :var2])
p1 = plot(longdf, ygroup="variable", x="x", y="value", Geom.subplot_grid(Geom.point))
p2 = plot(longdf, ygroup="variable", x="x", y="value", Geom.subplot_grid(Geom.point,
          free_y_axis=true))
hstack(p1,p2)
x 0.0 2.5 5.0 7.5 10.0 0 50 100 var2 0.0 2.5 5.0 7.5 10.0 var1 value by variable x 0.0 2.5 5.0 7.5 10.0 0 50 100 var2 0 50 100 var1 value by variable

Geom.vector

using Gadfly, RDatasets
set_default_plot_size(14cm, 14cm)

seals = RDatasets.dataset("ggplot2","seals")
seals[:Latb] = seals[:Lat] + seals[:DeltaLat]
seals[:Longb] = seals[:Long] + seals[:DeltaLong]
seals[:Angle] = atan2.(seals[:DeltaLat], seals[:DeltaLong])

coord = Coord.cartesian(xmin=-175.0, xmax=-119, ymin=29, ymax=50)
# Geom.vector also needs scales for both axes:
xsc  = Scale.x_continuous(minvalue=-175.0, maxvalue=-119)
ysc  = Scale.y_continuous(minvalue=29, maxvalue=50)
colsc = Scale.color_continuous(minvalue=-3, maxvalue=3)

layer1 = layer(seals, x=:Long, y=:Lat, xend=:Longb, yend=:Latb, color=:Angle,
               Geom.vector)

plot(layer1, xsc, ysc, colsc, coord)
Long -150 2 3 -2 -1 -3 0 1 Angle 30 35 40 45 50 Lat

Geom.vectorfield

using Gadfly, RDatasets
set_default_plot_size(21cm, 8cm)

coord = Coord.cartesian(xmin=-2, xmax=2, ymin=-2, ymax=2)
p1 = plot(coord, z=(x,y)->x*exp(-(x^2+y^2)),
          xmin=[-2], xmax=[2], ymin=[-2], ymax=[2],
# or:     x=-2:0.25:2.0, y=-2:0.25:2.0,
          Geom.vectorfield(scale=0.4, samples=17), Geom.contour(levels=6),
          Scale.x_continuous(minvalue=-2.0, maxvalue=2.0),
          Scale.y_continuous(minvalue=-2.0, maxvalue=2.0),
          Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(title="z"))

volcano = Matrix{Float64}(dataset("datasets", "volcano"))
volc = volcano[1:4:end, 1:4:end]
coord = Coord.cartesian(xmin=1, xmax=22, ymin=1, ymax=16)
p2 = plot(coord, z=volc, x=1.0:22, y=1.0:16,
          Geom.vectorfield(scale=0.05), Geom.contour(levels=7),
          Scale.x_continuous(minvalue=1.0, maxvalue=22.0),
          Scale.y_continuous(minvalue=1.0, maxvalue=16.0),
          Guide.xlabel("x"), Guide.ylabel("y"),
          Theme(key_position=:none))

hstack(p1,p2)
x 5 10 15 20 5 10 15 y x -2 -1 0 1 2 0.5 -0.5 0.0 z -2 -1 0 1 2 y

Geom.violin

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
Dsing = dataset("lattice","singer")
Dsing[:Voice] = [x[1:5] for x in Dsing[:VoicePart]]
plot(Dsing, x=:VoicePart, y=:Height, color=:Voice, Geom.violin)
VoicePart Soprano 1 Soprano 2 Alto 1 Alto 2 Tenor 1 Tenor 2 Bass 1 Bass 2 Sopra Alto Tenor Bass Voice 50 60 70 80 90 Height