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

Geom.subplot_grid with multiple layers #819

Open
Mattriks opened this issue Apr 2, 2016 · 2 comments
Open

Geom.subplot_grid with multiple layers #819

Mattriks opened this issue Apr 2, 2016 · 2 comments

Comments

@Mattriks
Copy link
Member

Mattriks commented Apr 2, 2016

Hi I'm using Julia 0.4.3 and Gadfly 0.4.2. Gadfly is nice!
Here is a plot:

using Gadfly
using DataFrames

function dsinc(r, x,y) 
    z = sqrt(x.^2 + y.^2)
    z = cos(z)./z - sin(z)./(z.^r)
    return DataFrame(x=x, y=y, z=(z+1), r="r=$r")
end


randu(n, u) = u*rand(n)-(u/2) 

srand(1234)
q = linspace(-10, 10, 40)
X = vcat([[i j] for i in q, j in q]...)
D1 = vcat([dsinc(r, X[:,1],X[:,2])  for r in 1:2]...)
D2 = DataFrame(x1=randu(8,18), y1=randu(8,18),col=3.0, id=[1,1,2,2,3,3,4,4], r="r=1")
D3 = DataFrame(x2=[0.,0.], y2=[0.,0.], col2=3.0, r=["r=1","r=2"])

coord = Coord.cartesian(xmin=-10.0, xmax=10.0, ymin=-10.0, ymax=10.0)

p = plot(
    Geom.subplot_grid(coord,
       layer(D1, x=:x, y=:y, color=:z, Geom.rectbin, order=1, xgroup=:r),
        layer(D2, x=:x1, y=:y1, color=:col, group=:id, Geom.line, order =2, xgroup=:r),
# layer(D3, x=:x2, y=:y2, color=:col2, Geom.point, order=3, xgroup=:r)
),
    Guide.title(join(["r=1","r=2"], " "^48)),
    Guide.xlabel("X<sub>1</sub>"),
    Guide.ylabel("X<sub>2</sub>"),
    Guide.colorkey("z")
)

fig1

And here are some issues:

i) When using multiple layers, the facet labels aren't automatically included on the plot. I have added a workaround here by putting them in Guide.title.

ii) For the layer with Geom.line, if I remove color=, and try to instead to do:
layer(D2, ..., Geom.line, Theme(default_color=colorant"red")) then I get an error. It seems that I am forced to "apply" the color scheme in the first layer to the second layer, as I have done in the above example. Also, bizarre things happen if I try replacing col=3.0, with col="red" in DataFrame D2.

iii) It would be nice to have a Geom.segment(x=, y=, xend=, yend=) to make it easier to add multiple lines, as in ggplot.

iv) I know Gadfly suggests not to do this if you try (even if you are facetting on the same variable):

plot(
    layer(D1, ..., xgroup=:r, Geom.subplot_grid(Geom.rectbin))
    layer(D2 ...., xgroup=:r, Geom.subplot_grid(Geom.line))
)

but as long as I'm facetting on the same variable e.g. xgroup=:r, I think that including Geom.subplot_grid within the layer is a nicer syntax than the otherway around. This syntax seems more appealing (to me) in adding a layer that is not facetted (i.e.where the same geoms appear on all subplots). Here is an example.If I uncomment the:

layer(D3, x=:x2, y=:y2, color=:col2, Geom.point, order=3, xgroup=:r)

in the above code, this results in strange behaviour. But then this third layer works if I comment out the first layer (the Geom.rectbin layer)!

@Vectornaut
Copy link

You can fix issue (i) by passing the data frame and the xgroup argument to the outer plot call, as shown in the test file layered_subplots.jl, instead of passing them to each layer call separately.

However, this only works when you're using the same data frame in every subplot.

@Mattriks
Copy link
Member Author

Mattriks commented Jun 9, 2016

Yes for i) also see my example in #840 and scatterplot matrix in #286.

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

2 participants