I want to plot multiple, somewhat unrelated datasets on one graph using algebra of graphics. i.e. I want some of the lines dashed, others dotted. Colors can random that is fine. Ideally I would have custom labels for each item.
I have been trying to achieve this, by creating a data object for each dataset and applying layers to it, but I am not sure how to make that work with having a nice legend. Plus this does not seem like a natural way to do this, using algebra of graphics functionality.
function filterPlot(filterPos; xlab = "", ylab="Blocking Intensity")
dataForPlot = nothing
vec_to_df((id, values)) = DataFrame(label = id, xx = 1:length(values), yy = values)
#filterPos is generaly a vector of vectors. We want to plot each of the vectors.
if filterPos[1] isa Array{<:Number,1}
counterj=1
dataForPlot = data(DataFrame(xx = 1:length(filterPos[1]), yy = filterPos[1]))*mapping(:1=>(t->t) ,:2 => (t->t))* visual( color = ColorSchemes.twelvebitrainbow[counterj])
for thing in filterPos[2:end]
counterj+=1
plotFilter = DataFrame(xx = 1:length(thing), yy = thing)
dataForPlot =dataForPlot + data(plotFilter)*mapping(:1=>(t->t) ,:2 => (t->t))*visual(color = ColorSchemes.twelvebitrainbow[counterj])
end
else
plotFilter = DataFrame(xx = 1:length(filterPos), yy = filterPos)
dataForPlot = data(plotFilter)*mapping(:xx=>(t->t) ,:yy => (t->t))
end
dataForPlot *= visual(Lines)
plaxis = (xlabel = xlab, ylabel = ylab)
drawing = draw(dataForPlot;axis = plaxis)
return drawing
end
edit: typo in code
The following plotting set up allows to individually vary colours and styles of the appearance of each data set on the plot as I wanted in the original question. (So really I already just settled for the solution given in my question, just cleaned it up a bit)
Suppose I have my data stored as vectors of vectors:
#My x values:
xdatas = [ xvalues1, xvalues2 ]
ydatas = [yvalues1, yvalues2]
myColor = anyColorSchemeILike
colorLength = length(myColor)
vec_to_df(j) = DataFrame(xx = xdatas[j], yy = ydatas[j])
dataForPlot = data(vec_to_df(1))*mapping(:xx, :yy)*visual(color = myColor[ 1 ] )
for j in 2:length(xdatas)
dataForPlot += data(vec_to_df(j))*mapping(:xx, :yy) *visual(color = myColor[ mod(j-1,colorLength-1)+1 ] )
end
actualFigure = Figure()
draw!(actualFigure[1,1], dataForPlot )