TidierOrg / TidierPlots.jl

Tidier data visualization in Julia, modeled after the ggplot2 R package.
MIT License
196 stars 7 forks source link

Functionality from `patchwork` #61

Closed rdboyes closed 1 month ago

rdboyes commented 4 months ago

Makie's grid layout system should allow implementation of a patchwork-like syntax for simple layouts. Initial implementation should include:

kdpsingh commented 4 months ago

I love patchwork and currently use it for an R package. I make use of the plot_layout() functionality to control the relative proportions of the plots.

If/when this is implemented, I will look forward to porting over my R package.

rdboyes commented 4 months ago

This is working as of the latest version:

using TidierPlots, DataFrames
df = DataFrame(x = [1, 2, 3], y = [2, 3, 4], z = [3, 4, 5])
p1 = ggplot(df) + geom_point(@aes(x, y))
p2 = ggplot(df) + geom_point(@aes(x, z))

p1 + p2

download

p1 / p2

download

Still need to implement plot_layout() though!

kdpsingh commented 4 months ago

Do we also support p1 | p2 for side by side plots?

rdboyes commented 4 months ago

We don’t, but we can! I never realized that was an operator in patchwork to be honest - is it exactly the same as + (which also puts plots side by side)?

rdboyes commented 4 months ago

bar operator supported as of https://github.com/TidierOrg/TidierPlots.jl/commit/1473747a60d6afe6fe403b136099e732137a319f

kdpsingh commented 4 months ago

Yes, same functionality as +

cnrrobertson commented 2 months ago

Been trying this out in 0.7.3 and really enjoying the simplicity of creating layouts with it. Would it be possible to extend this to multiple plots? i.e. plot1 | plot2 | plot3?

Currently, it is missing the function |(GGPlotGrid, GGPlot) to be able to combine grid objects with individual plots.

rdboyes commented 2 months ago

That's the plan! Just need to add some more functions and I haven't gotten around to it yet

If you want to give it a go, the GGPlotGrid struct contains a vector of the plots for exactly this reason (i.e. |(GGPlotGrid, GGPlot) should extract the plots from GGPlotGrid, append the GGPlot to that list, and return a new GGPlotGrid

cnrrobertson commented 2 months ago

With #95, we could now have:

t = ggplot(penguins) +
    geom_point(@aes(x = bill_length_mm, y = bill_depth_mm));

((t + t + t) | (t / t)) / t

and get test_patch

cnrrobertson commented 2 months ago

Working on plot_layout in #99. So far, functionality for rows, columns, widths, and heights are in.

t = ggplot(penguins) +
    geom_point(@aes(x = bill_length_mm, y = bill_depth_mm));

t + t + t + plot_layout(;nrow=2, heights=[3,1], widths=[1,2])

tvar

and its working with combination of previous grids and plots as well:

grid = (t + t + t) / t
grid + t + plot_layout(;nrow=2, heights=[1,2])

tvar2

rdboyes commented 2 months ago

This is amazing progress @cnrrobertson - I see the PR is still marked as draft, just let me know when you think its ready to be merged