Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subplot_grid - cols option? #855

Open
TransGirlCodes opened this issue Jun 16, 2016 · 4 comments
Open

subplot_grid - cols option? #855

TransGirlCodes opened this issue Jun 16, 2016 · 4 comments

Comments

@TransGirlCodes
Copy link

TransGirlCodes commented Jun 16, 2016

Hi, it's not obvious from the documentation, but I was wondering if subplot_grid has an ncol option in the same way as ggplot2's facet_wrap?
I have many groups for grouping the x axis, and it lays all the subplots out horizontally which squashes them, I'm looking for a way to make it split the row of subplots into multiple rows to avoid the squashing.

Thanks,
Ben.

@Mattriks
Copy link
Member

I don't think a facet_wrap has been implemented in Gadfly.
But here is an example (also see #841 for another way).

using DataFrames
x = linspace(-2, 2, 11)
f(a) = a*x+5.0*randn(11)
# First make some data, without indices:
D1 = vcat([DataFrame(x=x, y=f(a)) for a in linspace(2,16,8) ]...)
# Now make some col and row indices:
D2 = vcat([DataFrame(x=x, xg=col, yg=row)  for col in 1:4, row in 1:2  ]...)
# and concatenate:
D = hcat(D1,D2[:,2:3])

coord = Coord.cartesian(ymin=-50, ymax=50)
theme(x) = Theme(default_color=parse(Colors.Colorant, x))

 p = plot(D, xgroup=:xg, ygroup=:yg,
    Geom.subplot_grid(coord,
        layer(x=:x, y=:y, Geom.point, order=1),
        layer(x=:x, y=:y, Geom.smooth(method=:lm), theme("red"), order=2)
    ),
    Guide.xlabel("x"),
    Guide.ylabel("y")
)

You can stop the group labels from appearing by moving xgroup= and ygroup= into each layer.

@tbreloff
Copy link
Contributor

In case this isn't flexible enough for you, it's pretty straightforward in Plots:

ys = map(f,linspace(2,16,8))
scatter(x, ys, layout=(2,4), smooth=true, link=:all, lc=:red)

tmp

Note: you probably want to grab the master branch as I haven't tagged some bug fixes.

@tbenst
Copy link

tbenst commented Feb 21, 2021

I'm looking for how to do the equivalent of a facet_wrap in ggplot2 or seaborn, and this thread seems like the closest match for Gadfly. I'm guessing the prefered solution now is to put all individual plots into a vector, then reshape & plot with gridstack...? Do let me know if there's a more idiomatic solution. Thanks!

@Mattriks
Copy link
Member

Nope, no facet_wrap yet. Currently changing some internal code (#1520) which might make the development of subplot_wrap easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants