Gadfly plot adding layers using double loop & splatting

plotting

#1

Hello,

I’m trying to plot multiple layers with a pattern like the following:

p=plot( yintercept=[0,1,2,3],Geom.hline(color=colorant"darkgray", size=0pt) )
for m=0:3
q=append!(p.layers, [ layer( x=locs, y=BS[:,i]+m, Geom.line,Theme(default_color=colorant"red") ) for i in ind[m+1] ] … )
end

It’s essentially a double loop sytax to adding layers and currently it doesn’t work using append! and splatting together.

Would appreciate if any comment!


#2

I would prefer to do a more elaborate plot!

using DataFrames, Gadfly

function createDF(m::Int)
    i = ind[m+1]
    iln = length(i)
    DataFrame(x=repmat(locs, iln), y=vec(BS[:,i])+3*m, m="$m", i=repeat(i, inner=[n]))
end

n = 20
ind = [1:3, 4:5, 6:8, 9:10]
locs = [1:n;]
BS = randn(n, 10)
D = vcat([createDF(m) for m in 0:3]...)

p = plot(D, 
    layer(x=:x, y=:y, color=:m, group=:i, Geom.line),
    layer(yintercept=[0,1,2,3], Geom.hline(color=colorant"darkgray", size=0pt))
    )


#3

That’s a perfect answer! Thank you!