Skip to content

Commit

Permalink
aog
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarusA committed Jan 4, 2024
1 parent c378f92 commit 8697071
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 119 deletions.
2 changes: 1 addition & 1 deletion docs/gen_mds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OUTPUT = joinpath(@__DIR__, "src", "examples")

folders = readdir(joinpath(@__DIR__, "..", "examples"))
setdiff!(folders, [".DS_Store"])
setdiff!(folders, ["geo", "rpr", "aog", "datavis"])
setdiff!(folders, ["geo", "rpr", "datavis"])

function get_files(folders)
srcsfiles = []
Expand Down
23 changes: 22 additions & 1 deletion docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default defineConfig({
{ text: 'Dashboards', link: '/examples/dashboards/tesseral_spherical_harmonics' },
{ text: 'Data Visualization', link: '' },
{ text: 'Geo', link: '' },
{ text: 'Algebra of Graphics', link: '' },
{ text: 'Algebra of Graphics', link: '/examples/aog/penguins3d' },
{ text: 'Raytracing', link: '' }
]},
{ text: 'Pkgs versions', link: '/pkgs_versions' },
Expand Down Expand Up @@ -122,6 +122,7 @@ export default defineConfig({
{ text: 'contour_over_heatmap',link: '/examples/2d/contour/contour_over_heatmap' },
{ text: 'egg_shape',link: '/examples/2d/contour/egg_shape' },
{ text: 'qubit',link: '/examples/2d/contour/qubit' },
{ text: 'overlayed_functions',link: '/examples/2d/contour/overlayed_functions' },
],
},
{
Expand Down Expand Up @@ -395,6 +396,26 @@ export default defineConfig({
],
},
],
'/examples/aog/': [
{
text: 'AlgebraOfGraphics',
collapsed: true,
items: [
{ text: 'ablines', link: '/examples/aog/ablines' },
{ text: 'datasaurus', link: '/examples/aog/datasaurus' },
{ text: 'density_ridges', link: '/examples/aog/density_ridges' },
// { text: 'gapminder', link: '/examples/aog/gapminder' },
{ text: 'MarketData', link: '/examples/aog/MarketData' },
{ text: 'penguins', link: '/examples/aog/penguins' },
{ text: 'penguins3d', link: '/examples/aog/penguins3d' },
{ text: 'penguinsAoG', link: '/examples/aog/penguinsAoG' },
{ text: 'penguinsBoxes', link: '/examples/aog/penguinsBoxes' },
{ text: 'penguinsViolins', link: '/examples/aog/penguinsViolins' },
{ text: 'scatterlinesAoG', link: '/examples/aog/scatterlinesAoG' },
{ text: 'textScatterLines', link: '/examples/aog/textScatterLines' },
],
},
],

},
socialLinks: [
Expand Down
24 changes: 24 additions & 0 deletions examples/2d/contour/overlayed_functions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ## Multiple overlayed contour plots
using CairoMakie
CairoMakie.activate!(type = "svg") #hide

f(x, y) = abs(sin(x)* sin(y))
g(x, y) = abs(cos(x)* cos(y))

x = y = -3:0.1:3
zf = [f(x, y) for x in x, y in y]
zg = [g(x, y) for x in x, y in y]

fig = Figure(; size=(600, 400))
ax = Axis(fig[1,1]; xlabel="x", ylabel="y")
contour!(ax, x, y, zf; labels=true, color=:orangered, linestyle=:dash,
linewidth=2, label = "f(x,y)",
labelcolor=:red, levels = [0.5,1], labelsize=14)
contour!(ax, x, y, zg; labels=true, color=:dodgerblue, linewidth=2,
label = "g(x,y)", labelcolor=:blue, levels = [0.5,1], labelsize=14)
axislegend()
fig

save("overlayed_functions.svg", fig); # hide

# ![](overlayed_functions.svg)
12 changes: 9 additions & 3 deletions examples/aog/MarketData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ plt = data(cl)*mapping(:timestamp, :Close)*visual(Lines)
with_theme(theme_ggplot2(), size = (600,400)) do
plt |> draw
end
save("market_data.svg", current_figure()); # hide
save("market_data1.svg", current_figure()); # hide

# ![](market_data.svg)
# ![](market_data1.svg)


# ## Prices
Expand All @@ -24,7 +24,9 @@ plt *= mapping(:timestamp, labels .=> "value", color =dims(1)=>renamer(labels) =
with_theme(theme_light(), size = (600,400)) do
plt * visual(Lines) |> draw
end
save("market_data2.svg", current_figure()); # hide

# ![](market_data2.svg)
# ## StockChart

df = DataFrame(ohlc)
Expand All @@ -35,4 +37,8 @@ plt *= visual(BarPlot)

with_theme(theme_dark(), size = (800,500)) do
draw(plt, palettes =(; color = [:deepskyblue, :firebrick3]))
end
end

save("market_data3.svg", current_figure()); # hide

# ![](market_data3.svg)
9 changes: 8 additions & 1 deletion examples/aog/ablines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ with_theme(theme_ggplot2(), size = (600,400)) do
p_1to1 + p_not1to1 |> draw
end

save("ablines1.svg", current_figure()); # hide

# ![](ablines1.svg)

with_theme(theme_ggplot2(), size = (600,400)) do
fig = Figure()
ax = Axis(fig[1,1])
Expand All @@ -24,4 +28,7 @@ with_theme(theme_ggplot2(), size = (600,400)) do
legend!(fig[1, 2], aog)
Legend(fig[1,2], ax, valign = 0.2)
fig
end
end

save("ablines2.svg", current_figure()); # hide
# ![](ablines2.svg)
14 changes: 12 additions & 2 deletions examples/aog/datasaurus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ using CSV, Downloads, DataFrames
using AlgebraOfGraphics, CairoMakie
using Statistics
CairoMakie.activate!(type = "svg") #hide
# https://github.com/jumpingrivers/datasauRus
# https://www.autodesk.com/research/publications/same-stats-different-graphs

#https://github.com/jumpingrivers/datasauRus
#https://www.autodesk.com/research/publications/same-stats-different-graphs
link = "https://raw.githubusercontent.com/jumpingrivers/datasauRus/main/inst/extdata/DatasaurusDozen-Long.tsv"
file = Downloads.download(link)
dsaurus = CSV.read(file, DataFrame, delim = '\t')
Expand All @@ -14,6 +14,10 @@ with_theme(theme_light(), size = (1600,1200), fontsize = 24) do
draw(plt) ## palettes = (layout=wrap(cols=3),)
end

save("datasaurus1.svg", current_figure()); # hide

# ![](datasaurus1.svg)

# ## ggplot2 theme

with_theme(theme_ggplot2(), size = (1600,1200), fontsize = 24) do
Expand All @@ -26,7 +30,9 @@ with_theme(theme_ggplot2(), size = (1600,1200), fontsize = 24) do
delete!.(bxs[14:end])
fig
end
save("datasaurus2.svg", current_figure()); # hide

# ![](datasaurus2.svg)
# Adding some stats

gdf = groupby(dsaurus, :dataset);
Expand Down Expand Up @@ -56,3 +62,7 @@ with_theme(theme_dark(), size = (1600,1200), fontsize = 24) do
hidedecorations!(axstats)
fig
end

save("datasaurus3.svg", current_figure()); # hide

# ![](datasaurus3.svg)
36 changes: 21 additions & 15 deletions examples/aog/density_ridges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,32 @@ function getPenguins()
penguins = dropmissing(DataFrame(PalmerPenguins.load()))
return penguins
end
let
penguins = getPenguins()
## declare new plot attributes
palette = (color=tuple.(["#FC7808", "#8C00EC", "#107A78"], 0.65),
marker=[:circle, :utriangle, :rect])
cycle = Cycle([:color, :marker], covary=true)

p_len = data(penguins)
p_len = AoG.density()
p_len *= mapping(:flipper_length_mm => (t -> t / 10),
color=:species)

with_theme(theme_light(),size = (600,400), palette=palette, Scatter=(cycle=cycle,)) do
p_len |> draw
end

penguins = getPenguins()
## declare new plot attributes
palette = (color=tuple.(["#FC7808", "#8C00EC", "#107A78"], 0.65),
marker=[:circle, :utriangle, :rect])
cycle = Cycle([:color, :marker], covary=true)

p_len = data(penguins)
p_len *= AoG.density()
p_len *= mapping(:flipper_length_mm => (t -> t / 10), color=:species)

with_theme(theme_light(),size = (600,400), palette=palette, Scatter=(cycle=cycle,)) do
p_len |> draw
end

save("density_ridges1.png", current_figure()); # hide

# ![](density_ridges1.png)

p_len = data(penguins)
#p_len = AoG.density()
p_len *= mapping(:flipper_length_mm, color=:species)
p_len *= visual(AoG.Density, direction=:y, offset = 1.0,
alpha = 0.2, strokewidth = 1.5, strokecolor = :grey20)
draw(p_len)

save("density_ridges2.png", current_figure()); # hide

# ![](density_ridges2.png)
12 changes: 10 additions & 2 deletions examples/aog/gapminder.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using GLMakie, AlgebraOfGraphics, Dates
using Downloads, JSON, DataFrames, ColorSchemes, Colors
using FileIO, CSV
GLMakie.activate!()

# getting data
basepath = "https://raw.githubusercontent.com/vega/vega-datasets/master/data/"
gapminder = Downloads.download(basepath*"gapminder-health-income.csv");

#gapminder = JSON.parse(String(read(gapminder)), inttype=Float64);
df = CSV.File(gapminder) |> DataFrame
df = DataFrame(CSV.File(gapminder));

# selecting and plotting
colors = cgrad(:cividis, size(df,1), categorical=true)
p = data(df) *
mapping(:income, :health, color = :country =>(t -> string(t)),
markersize =:population => (t-> 8 + 70t/maximum(df.population))) *
visual(Scatter)
draw(p, axis=(xscale=log10,), palettes=(color=colors,))
draw(p, axis=(xscale=log10,), palettes=(color=colors,))

save("gapminder.png", current_figure()); # hide

# ![](gapminder.png)
6 changes: 5 additions & 1 deletion examples/aog/penguins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ function plotPenguins()
return fig
end
end
fig = plotPenguins()
fig = plotPenguins()

save("penguins.svg", fig); # hide

# ![](penguins.svg)
13 changes: 12 additions & 1 deletion examples/aog/penguins3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ with_theme(theme_ggplot2(),size = (600,400), palette=palstyle) do
draw(p3d; axis = (type = Axis3, perspectiveness = 0.5, aspect=(1, 1, 1)))
end

save("penguins3d_1.png", current_figure()); # hide

# ![](penguins3d_1.png)

# ## Penguins histogram

phist = data(penguins)
Expand All @@ -34,6 +38,9 @@ phist *= mapping(:bill_length_mm => "bill length mm", color =:species, stack = :
with_theme(theme_ggplot2(),size = (600,400), palette=palstyle) do
phist |> draw
end
save("penguins3d_2.png", current_figure()); # hide

# ![](penguins3d_2.png)

# ## AoG and plain Makie
# Currently, density plots with `direction=:y` is not supported by AoG,
Expand All @@ -57,4 +64,8 @@ with_theme(theme_ggplot2(),size = (600,400), palette=palstyle) do
rowgap!(fig.layout,0)
colgap!(fig.layout,0)
fig
end
end

save("penguins3d_3.png", current_figure()); # hide

# ![](penguins3d_3.png)
37 changes: 20 additions & 17 deletions examples/aog/penguinsAoG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ function getPenguins()
penguins = dropmissing(DataFrame(PalmerPenguins.load()))
return penguins
end
let
penguins = getPenguins()
## declare new plot attributes
palette = (color=tuple.(["#FC7808", "#8C00EC", "#107A78"], 0.65),
marker=[:circle, :utriangle, :rect])
cycle = Cycle([:color, :marker], covary=true)
## declare the dataset
p_len = data(penguins)
## declare the arguments of the analysis
p_len *= mapping(:flipper_length_mm => (t -> t / 10) => "flipper length (cm)",
:bill_length_mm => (t -> t / 10) => "bill length (cm)")
## declare the grouping and the respective visual attribute
p_len *= mapping(color=:species, marker=:species)

with_theme(theme_ggplot2(),size = (600,400), palette=palette, Scatter=(cycle=cycle,)) do
draw(p_len + p_len * linear();
axis = (; title="Flipper and bill length"))
end
penguins = getPenguins()
## declare new plot attributes
palette = (color=tuple.(["#FC7808", "#8C00EC", "#107A78"], 0.65),
marker=[:circle, :utriangle, :rect])
cycle = Cycle([:color, :marker], covary=true)
## declare the dataset
p_len = data(penguins)
## declare the arguments of the analysis
p_len *= mapping(:flipper_length_mm => (t -> t / 10) => "flipper length (cm)",
:bill_length_mm => (t -> t / 10) => "bill length (cm)")
## declare the grouping and the respective visual attribute
p_len *= mapping(color=:species, marker=:species)

with_theme(theme_ggplot2(),size = (600,400), palette=palette, Scatter=(cycle=cycle,)) do
draw(p_len + p_len * linear();
axis = (; title="Flipper and bill length"))
end

save("penguinsAoG.png", current_figure()); # hide

# ![](penguinsAoG.png)
Loading

0 comments on commit 8697071

Please sign in to comment.