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)
using Colors, Dates, Gadfly, RDatasets
Dp = dataset("ggplot2","presidential")[3:end,:]
De = dataset("ggplot2","economics")
De.Unemploy /= 10^3
plot(De, x=:Date, y=:Unemploy, Geom.line,
layer(Dp, xmin=:Start, xmax=:End, Geom.vband, color=:Party, alpha=[0.6]),
Scale.color_discrete_manual("deepskyblue", "lightcoral"),
Coord.cartesian(xmin=Date("1965-01-01"), ymax=12),
Guide.xlabel("Time"), Guide.ylabel("Unemployment (x10³)"), Guide.colorkey(title=""),
Theme(default_color="black", key_position=:top))
using ColorSchemes, DataFrames, Distributions, Gadfly
set_default_plot_size(21cm, 8cm)
x = range(-4, 4, length=30)
fn1(μ,x=x) = pdf.(Normal(μ, 1), x)
D = [DataFrame(x=x, y=fn1(μ), μ="$(μ)") for μ in [-1, 1]]
cpalette(p) = get(ColorSchemes.viridis, p)
p1 = plot(D[1], y=:y, x=:x, color=0:29, Geom.bar,
Scale.color_continuous(colormap=cpalette),
Theme(bar_spacing=-0.2mm, key_position=:none))
p2 = plot(D[1], x=:x, y=:y, Geom.bar, alpha=range(0.2,0.9, length=30))
p3 = plot(vcat(D...), x=:x, y=:y, color=:μ, alpha=[0.5],
Geom.bar(position=:identity))
hstack(p1, p2, p3)