View Source Tucan.Themes (tucan v0.1.0)
Helper functions for Tucan
theme.
A Tucan
theme is nothing more than a keyword list with a VegaLite
configuration
object with some styles applied and some metadata. Every theme must have the
following format:
[
theme: [], # the actual theme configuration
name: :name, # an atom with a unique name
doc: "description", # a description of the theme,
source: "url" # a url to the source of the theme if any for attribution
]
Default themes
Tucan
comes pre-packed with a set of themes, borrowed by the Vega Themes
project. You can set a theme to a plot by calling the Tucan.set_theme/2
function. If no
theme set the default vega-lite theme is used. In all examples below the following example
plot is used:
scatter =
Tucan.scatter(:iris, "petal_width", "petal_length", tooltip: true)
|> Tucan.color_by("species")
|> Tucan.shape_by("species")
lines = Tucan.lineplot(:stocks, "date", "price", color_by: "symbol", x: [type: :temporal])
area =
Tucan.area(:stocks, "date", "price", color_by: "symbol", mode: :normalize, x: [type: :temporal])
density = Tucan.density(:penguins, "Body Mass (g)", color_by: "Species", fill_opacity: 0.2)
strip =
Tucan.stripplot(:tips, "total_bill", group: "day", style: :jitter)
|> Tucan.color_by("sex")
boxplot = Tucan.boxplot(:penguins, "Body Mass (g)", color_by: "Species")
histogram = Tucan.histogram(:cars, "Horsepower", color_by: "Origin", fill_opacity: 0.5)
pie = Tucan.pie(:barley, "yield", "site", aggregate: :sum, tooltip: true)
donut = Tucan.donut(:barley, "yield", "site", aggregate: :sum, tooltip: true)
heatmap =
Tucan.density_heatmap(:penguins, "Beak Length (mm)", "Beak Depth (mm)", fill_opacity: 1.0)
first_row = VegaLite.concat(VegaLite.new(), [scatter, lines, area], :horizontal)
second_row =
VegaLite.concat(
VegaLite.new(),
[density, VegaLite.concat(VegaLite.new(), [strip, boxplot], :vertical), histogram],
:horizontal
)
third_row = VegaLite.concat(VegaLite.new(), [pie, donut, heatmap], :horizontal)
VegaLite.concat(VegaLite.new(), [first_row, second_row, third_row], :vertical)
|> VegaLite.config(legend: [disable: true])
|> VegaLite.resolve(:scale, color: :independent)
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","config":{"legend":{"disable":true}},"resolve":{"scale":{"color":"independent"}},"vconcat":[{"hconcat":[{"data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"color":{"field":"species"},"shape":{"field":"species"},"x":{"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":0.5,"tooltip":true,"type":"point"}},{"data":{"url":"https://vega.github.io/editor/data/stocks.csv"},"encoding":{"color":{"field":"symbol"},"x":{"field":"date","type":"temporal"},"y":{"field":"price","type":"quantitative"}},"mark":{"fillOpacity":0.5,"type":"line"}},{"data":{"url":"https://vega.github.io/editor/data/stocks.csv"},"encoding":{"color":{"field":"symbol"},"x":{"field":"date","type":"temporal"},"y":{"field":"price","stack":"normalize","type":"quantitative"}},"mark":{"fillOpacity":0.5,"line":false,"point":false,"type":"area"}}]},{"hconcat":[{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"field":"Species"},"x":{"field":"value","scale":{"zero":false},"type":"quantitative"},"y":{"field":"density","type":"quantitative"}},"mark":{"fillOpacity":0.2,"type":"area"},"transform":[{"counts":false,"cumulative":false,"density":"Body Mass (g)","groupby":["Species"],"maxsteps":200,"minsteps":25}]},{"vconcat":[{"data":{"url":"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv"},"encoding":{"color":{"field":"sex"},"x":{"field":"total_bill","type":"quantitative"},"y":{"field":"day","type":"nominal"},"yOffset":{"axis":null,"field":"jitter","type":"quantitative"}},"mark":{"size":16,"type":"point"},"transform":[{"as":"jitter","calculate":"sqrt(-2*log(random()))*cos(2*PI*random())"}]},{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"field":"Species"},"x":{"field":"Body Mass (g)","scale":{"zero":false},"type":"quantitative"},"y":{"field":"Species","type":"nominal"}},"mark":{"extent":1.5,"fillOpacity":0.5,"type":"boxplot"}}]},{"data":{"url":"https://vega.github.io/editor/data/cars.json"},"encoding":{"color":{"field":"Origin"},"x":{"bin":{"binned":true},"field":"bin_Horsepower","title":"Horsepower"},"x2":{"field":"bin_Horsepower_end"},"y":{"field":"count_Horsepower","stack":null,"type":"quantitative"}},"mark":{"fillOpacity":0.5,"type":"bar"},"transform":[{"as":"bin_Horsepower","bin":true,"field":"Horsepower"},{"aggregate":[{"as":"count_Horsepower","op":"count"}],"groupby":["bin_Horsepower","bin_Horsepower_end","Origin"]}]}]},{"hconcat":[{"data":{"url":"https://vega.github.io/editor/data/barley.json"},"encoding":{"color":{"field":"site"},"theta":{"aggregate":"sum","field":"yield","type":"quantitative"}},"mark":{"fillOpacity":0.5,"tooltip":true,"type":"arc"}},{"data":{"url":"https://vega.github.io/editor/data/barley.json"},"encoding":{"color":{"field":"site"},"theta":{"aggregate":"sum","field":"yield","type":"quantitative"}},"mark":{"fillOpacity":0.5,"innerRadius":50,"tooltip":true,"type":"arc"}},{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"aggregate":"count","type":"quantitative"},"x":{"bin":true,"field":"Beak Length (mm)","type":"quantitative"},"y":{"bin":true,"field":"Beak Depth (mm)","type":"quantitative"}},"mark":{"fillOpacity":1.0,"type":"rect"}}]}]}
The following themes are currently supported:
- ggplot2 - Chart theme modeled after
ggplot2
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","config":{"arc":{"fill":"#000"},"area":{"fill":"#000"},"axis":{"domain":false,"grid":true,"gridColor":"#FFFFFF","gridOpacity":1,"labelColor":"#7F7F7F","labelPadding":4,"tickColor":"#7F7F7F","tickSize":5.67,"titleFontSize":16,"titleFontWeight":"normal"},"group":{"fill":"#e5e5e5"},"legend":{"disable":true},"line":{"stroke":"#000"},"path":{"stroke":"#000"},"range":{"category":["#000000","#7F7F7F","#1A1A1A","#999999","#333333","#B0B0B0","#4D4D4D","#C9C9C9","#666666","#DCDCDC"]},"rect":{"fill":"#000"},"shape":{"stroke":"#000"},"symbol":{"fill":"#000","size":40}},"resolve":{"scale":{"color":"independent"}},"vconcat":[{"hconcat":[{"data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"color":{"field":"species"},"shape":{"field":"species"},"x":{"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":0.5,"tooltip":true,"type":"point"}},{"data":{"url":"https://vega.github.io/editor/data/stocks.csv"},"encoding":{"color":{"field":"symbol"},"x":{"field":"date","type":"temporal"},"y":{"field":"price","type":"quantitative"}},"mark":{"fillOpacity":0.5,"type":"line"}},{"data":{"url":"https://vega.github.io/editor/data/stocks.csv"},"encoding":{"color":{"field":"symbol"},"x":{"field":"date","type":"temporal"},"y":{"field":"price","stack":"normalize","type":"quantitative"}},"mark":{"fillOpacity":0.5,"line":false,"point":false,"type":"area"}}]},{"hconcat":[{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"field":"Species"},"x":{"field":"value","scale":{"zero":false},"type":"quantitative"},"y":{"field":"density","type":"quantitative"}},"mark":{"fillOpacity":0.2,"type":"area"},"transform":[{"counts":false,"cumulative":false,"density":"Body Mass (g)","groupby":["Species"],"maxsteps":200,"minsteps":25}]},{"vconcat":[{"data":{"url":"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv"},"encoding":{"color":{"field":"sex"},"x":{"field":"total_bill","type":"quantitative"},"y":{"field":"day","type":"nominal"},"yOffset":{"axis":null,"field":"jitter","type":"quantitative"}},"mark":{"size":16,"type":"point"},"transform":[{"as":"jitter","calculate":"sqrt(-2*log(random()))*cos(2*PI*random())"}]},{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"field":"Species"},"x":{"field":"Body Mass (g)","scale":{"zero":false},"type":"quantitative"},"y":{"field":"Species","type":"nominal"}},"mark":{"extent":1.5,"fillOpacity":0.5,"type":"boxplot"}}]},{"data":{"url":"https://vega.github.io/editor/data/cars.json"},"encoding":{"color":{"field":"Origin"},"x":{"bin":{"binned":true},"field":"bin_Horsepower","title":"Horsepower"},"x2":{"field":"bin_Horsepower_end"},"y":{"field":"count_Horsepower","stack":null,"type":"quantitative"}},"mark":{"fillOpacity":0.5,"type":"bar"},"transform":[{"as":"bin_Horsepower","bin":true,"field":"Horsepower"},{"aggregate":[{"as":"count_Horsepower","op":"count"}],"groupby":["bin_Horsepower","bin_Horsepower_end","Origin"]}]}]},{"hconcat":[{"data":{"url":"https://vega.github.io/editor/data/barley.json"},"encoding":{"color":{"field":"site"},"theta":{"aggregate":"sum","field":"yield","type":"quantitative"}},"mark":{"fillOpacity":0.5,"tooltip":true,"type":"arc"}},{"data":{"url":"https://vega.github.io/editor/data/barley.json"},"encoding":{"color":{"field":"site"},"theta":{"aggregate":"sum","field":"yield","type":"quantitative"}},"mark":{"fillOpacity":0.5,"innerRadius":50,"tooltip":true,"type":"arc"}},{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"aggregate":"count","type":"quantitative"},"x":{"bin":true,"field":"Beak Length (mm)","type":"quantitative"},"y":{"bin":true,"field":"Beak Depth (mm)","type":"quantitative"}},"mark":{"fillOpacity":1.0,"type":"rect"}}]}]}
- latimes - Chart theme modeled after the Los Angeles Times
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","config":{"arc":{"fill":"#82c6df"},"area":{"fill":"#82c6df"},"axis":{"labelFont":"Benton Gothic, sans-serif","labelFontSize":11.5,"labelFontWeight":"normal","titleFont":"Benton Gothic Bold, sans-serif","titleFontSize":13,"titleFontWeight":"normal"},"axisX":{"labelangle":0,"labelpadding":4,"ticksize":3},"axisY":{"labelbaseline":"middle","maxextent":45,"minextent":45,"ticksize":2,"titlealign":"left","titleangle":0,"titlex":-45,"titley":-11},"background":"#ffffff","legend":{"disable":true},"line":{"stroke":"#82c6df","strokeWidth":2},"path":{"stroke":"#82c6df"},"range":{"category":["#ec8431","#829eb1","#c89d29","#3580b1","#adc839","#ab7fb4"],"diverging":["#e68a4f","#f4bb6a","#f9e39c","#dadfe2","#a6b7c6","#849eae"],"heatmap":["#fbf2c7","#f9e39c","#f8d36e","#f4bb6a","#e68a4f","#d15a40","#ab4232"],"ordinal":["#fbf2c7","#f9e39c","#f8d36e","#f4bb6a","#e68a4f","#d15a40","#ab4232"],"ramp":["#fbf2c7","#f9e39c","#f8d36e","#f4bb6a","#e68a4f","#d15a40","#ab4232"]},"rect":{"fill":"#82c6df"},"shape":{"stroke":"#82c6df"},"symbol":{"fill":"#82c6df","size":30},"title":{"anchor":"start","color":"#000000","font":"Benton Gothic Bold, sans-serif","fontSize":22,"fontWeight":"normal"}},"resolve":{"scale":{"color":"independent"}},"vconcat":[{"hconcat":[{"data":{"url":"https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/0e7a9b0a5d22642a06d3d5b9bcbad9890c8ee534/iris.csv"},"encoding":{"color":{"field":"species"},"shape":{"field":"species"},"x":{"field":"petal_width","scale":{"zero":false},"type":"quantitative"},"y":{"field":"petal_length","scale":{"zero":false},"type":"quantitative"}},"mark":{"fillOpacity":0.5,"tooltip":true,"type":"point"}},{"data":{"url":"https://vega.github.io/editor/data/stocks.csv"},"encoding":{"color":{"field":"symbol"},"x":{"field":"date","type":"temporal"},"y":{"field":"price","type":"quantitative"}},"mark":{"fillOpacity":0.5,"type":"line"}},{"data":{"url":"https://vega.github.io/editor/data/stocks.csv"},"encoding":{"color":{"field":"symbol"},"x":{"field":"date","type":"temporal"},"y":{"field":"price","stack":"normalize","type":"quantitative"}},"mark":{"fillOpacity":0.5,"line":false,"point":false,"type":"area"}}]},{"hconcat":[{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"field":"Species"},"x":{"field":"value","scale":{"zero":false},"type":"quantitative"},"y":{"field":"density","type":"quantitative"}},"mark":{"fillOpacity":0.2,"type":"area"},"transform":[{"counts":false,"cumulative":false,"density":"Body Mass (g)","groupby":["Species"],"maxsteps":200,"minsteps":25}]},{"vconcat":[{"data":{"url":"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv"},"encoding":{"color":{"field":"sex"},"x":{"field":"total_bill","type":"quantitative"},"y":{"field":"day","type":"nominal"},"yOffset":{"axis":null,"field":"jitter","type":"quantitative"}},"mark":{"size":16,"type":"point"},"transform":[{"as":"jitter","calculate":"sqrt(-2*log(random()))*cos(2*PI*random())"}]},{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"field":"Species"},"x":{"field":"Body Mass (g)","scale":{"zero":false},"type":"quantitative"},"y":{"field":"Species","type":"nominal"}},"mark":{"extent":1.5,"fillOpacity":0.5,"type":"boxplot"}}]},{"data":{"url":"https://vega.github.io/editor/data/cars.json"},"encoding":{"color":{"field":"Origin"},"x":{"bin":{"binned":true},"field":"bin_Horsepower","title":"Horsepower"},"x2":{"field":"bin_Horsepower_end"},"y":{"field":"count_Horsepower","stack":null,"type":"quantitative"}},"mark":{"fillOpacity":0.5,"type":"bar"},"transform":[{"as":"bin_Horsepower","bin":true,"field":"Horsepower"},{"aggregate":[{"as":"count_Horsepower","op":"count"}],"groupby":["bin_Horsepower","bin_Horsepower_end","Origin"]}]}]},{"hconcat":[{"data":{"url":"https://vega.github.io/editor/data/barley.json"},"encoding":{"color":{"field":"site"},"theta":{"aggregate":"sum","field":"yield","type":"quantitative"}},"mark":{"fillOpacity":0.5,"tooltip":true,"type":"arc"}},{"data":{"url":"https://vega.github.io/editor/data/barley.json"},"encoding":{"color":{"field":"site"},"theta":{"aggregate":"sum","field":"yield","type":"quantitative"}},"mark":{"fillOpacity":0.5,"innerRadius":50,"tooltip":true,"type":"arc"}},{"data":{"url":"https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"},"encoding":{"color":{"aggregate":"count","type":"quantitative"},"x":{"bin":true,"field":"Beak Length (mm)","type":"quantitative"},"y":{"bin":true,"field":"Beak Depth (mm)","type":"quantitative"}},"mark":{"fillOpacity":1.0,"type":"rect"}}]}]}
Summary
Functions
Returns the configuration object for the given theme.
Functions
Returns the configuration object for the given theme.
An exception will be raised if the theme name is invlaid.