using DataFrames
using RDatasets
using Gadfly
plot(x=randn(20), y=randn(20))
plot(x=rand(10), y=rand(10), Geom.point, Geom.line)
plot(x=1:10, y=2 .^ rand(10), Scale.y_sqrt, Geom.point, Geom.smooth,
Guide.xlabel("Stimulus"), Guide.ylabel("Response"), Guide.title("Dog Training"))
plt = plot(..)
draw(SVG("myplot.svg", 4inch, 3inch), plt)
draw(PNG("myplot.png", 4inch, 3inch), plt)
draw(PDF("myplot.pdf", 4inch, 3inch), plt)
draw(PS("myplot.ps", 4inch, 3inch), plt)
draw(D3("myplot.js", 4inch, 3inch), plt)
If save to png file, you will need this:
import Cairo, Fontconfig
draw(SVGJS("foo.svg", 12cm, 9cm), plt)
<img src="foo.svg"/>
<object data="foo.svg" type="image/svg+xml"></object>
iris = dataset("datasets", "iris")
plot(iris, x="SepalLength", y="SepalWidth", Geom.point)
plot(dataset("car", "SLID"), x="Wages", color="Language", Geom.histogram)
plot(x -> sin(x)/x, 0.001, 1000, Scale.x_log)
plot([sin, cos], 0, 25)
diamonds = dataset("ggplot2", "diamonds")
plot(diamonds, x="Price", color="Cut", Geom.histogram)
plot(diamonds, x="Price", color="Cut", Geom.density)
plot(iris, x="SepalLength", y="SepalWidth", Geom.point)
using Distributions
mn = MultivariateNormal([0.0, 0.0], [1.0 0.01; 0.01 1.0])
X = rand(mn, 10000)
plot(x=X[1,:], y=X[2,:], Geom.hexbin)
plot(iris, x="SepalLength", y="SepalWidth", Geom.point, Geom.density2d(levels=4))
plot(z=(x,y) -> x*exp(-(x-round(Int, x))^2-y^2),
x=range(-8,stop=8,length=150), y=range(-2,stop=2,length=150), Geom.contour)
volcano = convert(Array{Float64}, dataset("datasets", "volcano"))
plot(z=volcano, Geom.contour)
coord = Coord.cartesian(xmin=-2, xmax=2, ymin=-2, ymax=2)
plot(coord, z=(x,y)->x*exp(-(x^2+y^2)), x=-2:0.25:2.0, y=-2:0.25:2.0,
Geom.vectorfield(scale=0.4), Geom.contour(levels=6),
Scale.x_continuous(minvalue=-2.0, maxvalue=2.0),
Scale.y_continuous(minvalue=-2.0, maxvalue=2.0))
plot(dataset("lattice", "singer"), x="VoicePart", y="Height", Geom.boxplot)
plot(dataset("lattice", "singer"), x="VoicePart", y="Height", Geom.beeswarm)
plot(dataset("lattice", "singer"), x="VoicePart", y="Height", Geom.violin)
longley = dataset("datasets", "longley")
p = plot(longley, x="Year", y="Employed", Geom.line)
plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin)
plot(dataset("car", "Womenlf"), x="HIncome", y="Region", Geom.histogram2d)
xdata = sort(iris.SepalWidth)
ydata = cumsum(xdata);
line = layer(x=xdata, y=ydata, Geom.line, Theme(default_color="red"))
bars = layer(iris, x=:SepalWidth, Geom.bar)
plot(line, bars)
p = plot()
push!(p, layer(x=[2,4], y=[2,4], size=[1.4142], color=[colorant"red"]))
push!(p, Coord.cartesian(fixed=true))
push!(p, Guide.title("Red dots"))
plot(iris, xgroup="Species", x="SepalLength", y="SepalWidth", Geom.subplot_grid(Geom.point))
plot(iris, ygroup="Species", x="SepalLength", y="SepalWidth", Geom.subplot_grid(Geom.point))
fig1a = plot(iris, x=:SepalLength, y=:SepalWidth, Geom.point)
fig1b = plot(iris, x=:SepalLength, Geom.density, Coord.cartesian(xmin=4, xmax=8))
vstack(fig1a,fig1b)
fig1c = plot(iris, x=:SepalWidth, Geom.density, Coord.cartesian(xmin=2, xmax=4.5))
fig1d = plot(iris, x=:PetalWidth, Geom.density, Coord.cartesian(xmin=0., xmax=3.))
gridstack([fig1a fig1c; fig1b fig1d])
plot(iris, x=:SepalLength, y=:SepalWidth, Geom.point,
Theme(discrete_highlight_color=x->"red", default_color="white"))
gasoline = dataset("Ecdat", "Gasoline")
plot(gasoline, x=:Year, y=:LGasPCar, color=:Country, Geom.point, Geom.line)
latex_fonts = Theme(major_label_font="CMU Serif", major_label_font_size=16pt,
key_label_font="CMU Serif", key_label_font_size=10pt)
Gadfly.push_theme(latex_fonts)
gasoline = dataset("Ecdat", "Gasoline")
p = plot(gasoline, x=:Year, y=:LGasPCar, color=:Country, Geom.point, Geom.line)
Gadfly.pop_theme();
Gadfly.with_theme(latex_fonts) do
plot(gasoline, x=:Year, y=:LGasPCar, color=:Country, Geom.point, Geom.line)
end
Gadfly.with_theme(:dark) do
plot(iris, x=:SepalLength, y=:SepalWidth, color=:Species)
end
Gadfly.get_theme(::Val{:orange}) = Theme(default_color="orange")
Gadfly.with_theme(:orange) do
plot(iris, x=:SepalWidth, Geom.bar)
end
using Plots, StatsPlots, Distances, Clustering
WARNING: using Plots.plot in module Main conflicts with an existing identifier.
haireyecolor = dataset("datasets", "HairEyeColor")
haircolor = by(haireyecolor, :Hair, Freq=:Freq => sum)
pie(haircolor[!, :Hair], haircolor[!, :Freq]; size=(250, 200))
D = pairwise(Euclidean(), Matrix(iris[:, 1:4]), dims=1)
result = hclust(D, linkage=:single);
StatsPlots.plot(result)
n = 5000
x = randn(n)
y = -0.5x + randn(n)
marginalhist(x, y, fc=:plasma, bins=40)
┌ Warning: Attribute alias `ylabel` detected in the plot recipe defined for the signature (::Type{Val{:marginalhist}}, ::AbstractPlot). To ensure expected behavior it is recommended to use the default attribute `yguide`. └ @ Plots /home/yuehhua/.julia/packages/Plots/8GUYs/src/pipeline.jl:15 ┌ Warning: Attribute alias `xlabel` detected in the plot recipe defined for the signature (::Type{Val{:marginalhist}}, ::AbstractPlot). To ensure expected behavior it is recommended to use the default attribute `xguide`. └ @ Plots /home/yuehhua/.julia/packages/Plots/8GUYs/src/pipeline.jl:15 ┌ Warning: Attribute alias `ylabel` detected in the plot recipe defined for the signature (::Type{Val{:marginalhist}}, ::AbstractPlot). To ensure expected behavior it is recommended to use the default attribute `yguide`. └ @ Plots /home/yuehhua/.julia/packages/Plots/8GUYs/src/pipeline.jl:15 ┌ Warning: Attribute alias `xlabel` detected in the plot recipe defined for the signature (::Type{Val{:marginalhist}}, ::AbstractPlot). To ensure expected behavior it is recommended to use the default attribute `xguide`. └ @ Plots /home/yuehhua/.julia/packages/Plots/8GUYs/src/pipeline.jl:15
n = 500
x = range(-8., stop=8., length=n)
y = range(-2., stop=2., length=n)
f(x,y) = x*exp(-(x-round(Int, x))^2-y^2)
f (generic function with 1 method)
Plots.plot(x, y, f, st=:surface)
@gif for i in range(0, stop=2π, length=100)
p = Plots.plot(x, y, f, st=:surface)
Plots.plot!(p, camera=(15*cos(i), 40))
end
┌ Info: Saved animation to │ fn = /media/yuehhua/Workbench/Lessons/julia_programming/materials/tmp.gif └ @ Plots /home/yuehhua/.julia/packages/Plots/8GUYs/src/animation.jl:102