GithubHelp home page GithubHelp logo

sethaxen / algebraofgraphics.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makieorg/algebraofgraphics.jl

0.0 2.0 0.0 42 KB

Combine ingredients for a plot

License: MIT License

Julia 100.00%

algebraofgraphics.jl's Introduction

AlgebraOfGraphics

Build Status codecov.io

Define a "plotting package agnostic" algebra of graphics based on a few simple building blocks that can be combined using * and +. Highly experimental proof of concept. Requires the branch StatsMakie/pv/aog to work in conjunction with Makie.

Demo

using RDatasets: dataset

using StatsMakie: linear
using AbstractPlotting, GLMakie

using AlgebraOfGraphics: Data, Select, Group

mpg = dataset("ggplot2", "mpg");
cols = Data(mpg) * Select(:Displ, :Hwy);
grp = Group(color = :Cyl);

plot(Scatter * cols * Attributes(markersize=10px))

test

# Now I can simply add `grp` to do the grouping
plot(Scatter * cols * grp * Attributes(markersize=10px))

test

# This is almost a recipe with scatter and linear regression :)
# It can be applied to the arguments just by multiplying them
plots = Scatter * Attributes(markersize = 10px) + linear * Attributes(linewidth = 5)
plot(plots * cols)

test

# Again, if I multiply by the grouping, I add it to the scene
plot(plots * cols * grp)

test

# This is a more complex example, where I want to split the scatter,
# but do the linear regression with all the data
different_grouping = grp * Scatter * Attributes(markersize = 10px) + linear * Attributes(linewidth = 5)
plot(cols * different_grouping)

test

Pipeline

Under the hood, Group and Select are combined into a Traces object, which contains a list of "traces" to be plotted, indexed by some primary keys, that will be used also to style the plot. The Traces object can also be passed by hand. It needs to iterate Pair{NamedTuple, Select}, where the named tuple acts as a "primary key". If there are multiple Traces objects, all the "consistent options" are kept (i.e. where the shared primary keys match). If the primary keys are "disjoint", all combinations are allowed. counter simply gives values from 1 to n to all the attributes that are passed to it as symbols.

Examples

julia> using AlgebraOfGraphics: Select, Traces

julia> ts1 = Select(rand(10));

julia> ts2 = Traces(counter(:color), eachcol(rand(10, 3)));

julia> plot(Scatter * ts1 * ts2, markersize = 10px)

test

julia> ts1 = Traces(counter(:marker), eachcol(rand(10, 3)));

julia> ts2 = Traces(counter(:color), eachcol(rand(10, 3)));

julia> plot(Scatter * ts1 * ts2, markersize = 10px)

test

The framework does not requires that the objects listed in Traces are columns. They could be anything that the plotting package can deal with.

julia> ts1 = Traces(counter(:color), [-pi..0, 0..pi]);

julia> ts2 = Traces(counter(:linestyle), [sin, cos]);

julia> plot(ts1 * ts2, linewidth = 10)

test

algebraofgraphics.jl's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.