TidierPlots.jl
What is TidierPlots.jl?
TidierPlots.jl is a 100% Julia implementation of the R package ggplot in Julia. Powered by AlgebraOfGraphics.jl, Makie.jl, and Julia’s extensive meta-programming capabilities, TidierPlots.jl is an R user’s love letter to data visualization in Julia.
TidierPlots.jl
has three goals, which differentiate it from other plotting packages in Julia:
-
Stick as closely to tidyverse syntax and behaviour as possible: Whereas other meta-packages introduce Julia-centric idioms for working with plots, this package’s goal is to reimplement ggplot in Julia. This currently just means that
TidierPlots.jl
gives the option for specifyingaes
with the macro@es
to allow unquoted column references, but the use of macros may need to expand as more features are added. -
Stay as compatible as possible with AlgebraOfGraphics.jl This package is meant to be a thin wrapper around AoG's syntax to help introduce R users to plotting in Julia.
Geom
objects declared in TidierPlots.jl can be easily converted to AoGLayer
objects usingLayer(Geom)
, andGGPlot
objects can be converted to AoGLayers
objects usingLayers(GGPlot)
. -
To Extend ggplot using julia-specific features where appropriate as long as this does not confict with the first two goals. The package aims to behave exactly like ggplot unless told otherwise. Additional options and parameters that are not present in ggplot may be added, but options that are present in R's ggplot should behave the way they do in R.
Installation
For the "stable" version, access the Pkg interface by pressing ]
at the julia>
prompt, then type add TidierPlots
.
For the development version:
using Pkg
Pkg.add(url="https://github.com/TidierOrg/TidierPlots.jl")
What functions does TidierPlots.jl support?
TidierPlots.jl currently supports the top-level function ggplot()
, plus:
Geoms:
geom_point
geom_smooth
geom_errorbar
geom_path
,geom_line
, andgeom_step
geom_bar
,geom_col
, andgeom_histogram
geom_boxplot
andgeom_violin
geom_contour
andgeom_tile
geom_density
geom_text
andgeom_label
Makie Themes:
theme_ggplot2()
(the default)theme_dark()
theme_black()
theme_light()
theme_minimal()
Colour Scales:
scale_colo[u]r_manual()
- give a list of hexvalues
enclosed inc()
to define a scalescale_colo[u]r_[discrete|continuous]()
- setpalette =
a Makie palette.
Facetting:
facet_wrap
: Specifyfacets
variable.facet_grid
: Specifyrows
and/orcols
.
Additional Elements:
scale_[x|y]_[continuous|log[ |2|10]|logit|pseudolog10|sqrt|reverse]
labs
lims
Differences from ggplot2
The goal of this package is to allow you to write code that is as similar to ggplot2 code as possible. The only difference in basic usage is in the aes()
function. TidierPlots.jl accepts multiple forms for aes specification, none of which is exactly the same as ggplot2.
- Option 1:
@aes
macro, aes as in ggplot, e.g.@aes(x = x, y = y)
- Option 2:
@es
macro, aes as in ggplot, e.g.@es(x = x, y = y)
- Option 3:
aes
function, julia-style columns, e.g.aes(x = :x, y = :y)
- Option 4:
aes
function, strings for columns, e.g.aes(x = "x", y = "y")
Specifying aes options positionally, e.g. aes("x", "y")
is not yet supported.
Display Options
Use the function TidierPlots_set(option::String, value::Bool)
to control display options. The following options are supported:
- "plot_show" (default true). Enables
ggplot
-like behaviour where plots are displayed when created. - "plot_log" (default true). Prints a text summary of the properties of the ggplot
Example
Let's make a plots using the Palmer Penguins data from PalmerPenguins.jl
:
using TidierPlots
using DataFrames
using PalmerPenguins
penguins = dropmissing(DataFrame(PalmerPenguins.load()))
ggplot(penguins, aes(x = "bill_length_mm", y = "bill_depth_mm", color = "species")) +
geom_point() +
geom_smooth(method = "lm") +
labs(x = "Bill Length (mm)", y = "Bill Width (mm)",
title = "Bill Length vs. Bill Width",
subtitle = "Using geom_point and geom_smooth") +
theme_dark()
See the documentation for many more examples.
What's New
See NEWS.md for the latest updates.
What's Missing
Lots! Please feel free to file an issue and/or submit a pull request to add additional ggplot-based features. If it is in ggplot, we want to add it.