Gadfly - plot with several graphs, suitable for publications

I’ve lost quite a lot of time to figure our how to include different line styles on graphs with different colors, so it is suitable for black&white publications. After several switching from package to package I’ve decided to stick with Gadfly, and here is my solution, hope it helps.

I have 4 algorithms that I test on different problems and I want the plot to include graph for each algorithm. Sometimes I use only some of the algorithms and I do not want to change the code each time.

  algs=[1,2,3,4] #the only line I change
  c=Scale.color_discrete_hue() #c.f(4) - vector of first 4 colors
  #for black&white:
  dash = 4 * Compose.mm
  dot = .5 * Compose.mm
  gap = 1 * Compose.mm
  lines=[[],[dash],[dot],[dash,gap,dot,gap]]
legend=["―― method1",
            "– – – method2",
            "‐‐‐‐‐ method3",
            "– ‐ – method4"] 
  plot([layer(x=varx, y=vary, Geom.line,
         Theme(default_color=color(c.f(4)[a]),line_style=lines[a])) for a in algs]...,
                 Guide.manual_color_key("Method",legend[algs],c.f(4)[algs]))

The result is below. The strings in legend get messed up when converted from SVG to PNG to upload here, maybe someone else knows how to fix that.

Why can’t you just include the Unicode character straight in the strings? It would perhaps be nice to show a figure of the result as well, for people who are on their mobile or haven’t got Gadfly installed etc.

Thanks for your comments. I’ve updated the post.