Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Faceting #80

Closed
greimel opened this issue Jul 10, 2019 · 2 comments
Closed

Faceting #80

greimel opened this issue Jul 10, 2019 · 2 comments
Labels

Comments

@greimel
Copy link

greimel commented Jul 10, 2019

I often want to group and facet plots. That's why I mostly call ggplot2 via RCall.jl so far. I played around a litte bit. I thought I share what I have so that other can start from here.
Basic faceting looks like this:

Auswahl_004

What I did is

  1. Group the data (using DataFrames.jl)
  2. Create panels for each group
  3. Adjust the limits across all panels
  4. remove the axis name everywhere except at the boundary
  5. add titles for each panel

What's still to improve

  1. I tried to remove the axis ticknames, but my function doesn't work.
  2. Removing the axis names messed up the alignment of the panels
  3. I would like to have only one x instead of a label in each scene.
  4. The titles of the panels to too big and the gap between the plot and the title is too big. Ideally there could be a visual link like in ggplot2.

compare ggplot2 (copied from the manual)
image

Julia code for the plot at the top:

using Makie, StatsMakie, Random, DataFrames
N = 100
x = randn(N)
y = randn(N)
g1 = rand(["color $i" for i in 1:3], N)
g2 = rand(["marker $i" for i in 1:3], N)

df = DataFrame(x=x, y=y, g1=g1, g2=g2)

# common_limits
function min_range(vec)
  min, max = extrema(vec)
  range = max - min
  min, range
end

function box(x, y)
  x_min, x_range = min_range(x)
  y_min, y_range = min_range(y)
  FRect(x_min, y_min, x_range, y_range)
end

# omit axis annotations and labels for all but left

function omit_y_name!(axis)
  old_names = axis[:names][:axisnames].val
  axis[:names][:axisnames] = (old_names[1], "")
end

## Doesn't work
function omit_y_tickslabels!(axis)
  @show old_labels = axis[:ticks][:labels].val
  axis[:ticks][:labels] = (old_labels[1], old_labels[2] .^ 0)
end

faceted_scene = map(enumerate(groupby(df, :g1))) do isubdf
  i, subdf = isubdf
  scn = scatter(Data(subdf), :x, :y, limits=box(df[:x], df[:y]))
  i != 1 && omit_y_name!(scn[Axis])
  title(scn, string(subdf[:g1][1]))
end |> vbox

I also played a bit with legends for grouped data here.

@asinghvi17
Copy link
Member

Hey @greimel,

Makie's support for layouting isn't the best at the moment, because everything lives in data coordinates. We're working on solutions to this - @jkrumbiegel kindly provided a layout constraint solver - and it is certainly planned to integrate that (hopefully, by moving the axis out of data space).

In its current state, it's unlikely that what you're proposing is possible in Makie. However, it's absolutely the intention that things like that be made possible in the future.

@asinghvi17
Copy link
Member

This is possible now with https://github.com/jkrumbiegel/MakieLayout!

@piever piever added the vizcon label Mar 6, 2020
@greimel greimel closed this as completed Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants