Geometries

Geometries

Geom.abline

using Gadfly, RDatasets, Compose, Random
Random.seed!(123)
set_default_plot_size(21cm, 8cm)

p1 = 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"))))

x = [20*rand(20); exp(-3)]
D = DataFrame(x=x, y= exp.(-0.5*asinh.(x).+5) .+ 2*randn(length(x)))
abline = Geom.abline(color="red", style=:dash)
p2 = plot(D, x=:x, y=:y,  Geom.point,  Scale.x_asinh, Scale.y_log,
     intercept=[148], slope=[-0.5], abline)
hstack(p1, p2)
x sinh(-5) sinh(-4) sinh(-3) sinh(-2) sinh(-1) sinh(0) sinh(1) sinh(2) sinh(3) sinh(4) sinh(5) sinh(6) sinh(7) sinh(8) sinh(9) sinh(-4.0) sinh(-3.8) sinh(-3.6) sinh(-3.4) sinh(-3.2) sinh(-3.0) sinh(-2.8) sinh(-2.6) sinh(-2.4) sinh(-2.2) sinh(-2.0) sinh(-1.8) sinh(-1.6) sinh(-1.4) sinh(-1.2) sinh(-1.0) sinh(-0.8) sinh(-0.6) sinh(-0.4) sinh(-0.2) sinh(0.0) sinh(0.2) sinh(0.4) sinh(0.6) sinh(0.8) sinh(1.0) sinh(1.2) sinh(1.4) sinh(1.6) sinh(1.8) sinh(2.0) sinh(2.2) sinh(2.4) sinh(2.6) sinh(2.8) sinh(3.0) sinh(3.2) sinh(3.4) sinh(3.6) sinh(3.8) sinh(4.0) sinh(4.2) sinh(4.4) sinh(4.6) sinh(4.8) sinh(5.0) sinh(5.2) sinh(5.4) sinh(5.6) sinh(5.8) sinh(6.0) sinh(6.2) sinh(6.4) sinh(6.6) sinh(6.8) sinh(7.0) sinh(7.2) sinh(7.4) sinh(7.6) sinh(7.8) sinh(8.0) sinh(-5) sinh(0) sinh(5) sinh(10) sinh(-4.0) sinh(-3.5) sinh(-3.0) sinh(-2.5) sinh(-2.0) sinh(-1.5) sinh(-1.0) sinh(-0.5) sinh(0.0) sinh(0.5) sinh(1.0) sinh(1.5) sinh(2.0) sinh(2.5) sinh(3.0) sinh(3.5) sinh(4.0) sinh(4.5) sinh(5.0) sinh(5.5) sinh(6.0) sinh(6.5) sinh(7.0) sinh(7.5) sinh(8.0) h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? e0.5 e1.0 e1.5 e2.0 e2.5 e3.0 e3.5 e4.0 e4.5 e5.0 e5.5 e6.0 e6.5 e7.0 e7.5 e0.0 e0.1 e0.2 e0.3 e0.4 e0.5 e0.6 e0.7 e0.8 e0.9 e1.0 e1.1 e1.2 e1.3 e1.4 e1.5 e1.6 e1.7 e1.8 e1.9 e2.0 e2.1 e2.2 e2.3 e2.4 e2.5 e2.6 e2.7 e2.8 e2.9 e3.0 e3.1 e3.2 e3.3 e3.4 e3.5 e3.6 e3.7 e3.8 e3.9 e4.0 e4.1 e4.2 e4.3 e4.4 e4.5 e4.6 e4.7 e4.8 e4.9 e5.0 e5.1 e5.2 e5.3 e5.4 e5.5 e5.6 e5.7 e5.8 e5.9 e6.0 e6.1 e6.2 e6.3 e6.4 e6.5 e6.6 e6.7 e6.8 e6.9 e7.0 e0 e2 e4 e6 e8 e0.0 e0.2 e0.4 e0.6 e0.8 e1.0 e1.2 e1.4 e1.6 e1.8 e2.0 e2.2 e2.4 e2.6 e2.8 e3.0 e3.2 e3.4 e3.6 e3.8 e4.0 e4.2 e4.4 e4.6 e4.8 e5.0 e5.2 e5.4 e5.6 e5.8 e6.0 e6.2 e6.4 e6.6 e6.8 e7.0 y Cty -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 -50 0 50 100 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 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 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? y=x -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 -50 -48 -46 -44 -42 -40 -38 -36 -34 -32 -30 -28 -26 -24 -22 -20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 -50 0 50 100 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Hwy

Geom.bar

using Gadfly, RDatasets
set_default_plot_size(14cm, 8cm)
plot(dataset("HistData", "ChestSizes"), x="Chest", y="Count", Geom.bar)
Chest 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 0 20 40 60 80 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -2000 -1500 -1000 -500 0 500 1000 1500 2000 2500 3000 3500 -1500 -1450 -1400 -1350 -1300 -1250 -1200 -1150 -1100 -1050 -1000 -950 -900 -850 -800 -750 -700 -650 -600 -550 -500 -450 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 -2000 0 2000 4000 -1500 -1400 -1300 -1200 -1100 -1000 -900 -800 -700 -600 -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 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 h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 -400 -380 -360 -340 -320 -300 -280 -260 -240 -220 -200 -180 -160 -140 -120 -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 600 620 640 660 680 700 720 740 760 780 800 -500 0 500 1000 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 Frequency Sex Male Female Brown Blue Hazel Green Eye h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -500 -400 -300 -200 -100 0 100 200 300 400 500 600 700 800 900 -400 -380 -360 -340 -320 -300 -280 -260 -240 -220 -200 -180 -160 -140 -120 -100 -80 -60 -40 -20 0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 600 620 640 660 680 700 720 740 760 780 800 -500 0 500 1000 -400 -350 -300 -250 -200 -150 -100 -50 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 Frequency Sex Male Female Brown Blue Hazel Green Eye h,j,k,l,arrows,drag to pan i,o,+,-,scroll,shift-drag to zoom r,dbl-click to reset c for coordinates ? for help ? -200 -150 -100 -50 0 50 100 150 200 250 300 350 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 -75 -70 -65 -60 -55 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 -200 0 200 400 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 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