# Gadfly - plot with several graphs, suitable for publications

**URL:** <https://discourse.julialang.org/t/gadfly-plot-with-several-graphs-suitable-for-publications/3718>\
**Category:** Visualization\
**Created:** [May 15, 2017, 2:03pm UTC](https://discourse.julialang.org/t/gadfly-plot-with-several-graphs-suitable-for-publications/3718 "2017-05-15T14:03:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanaperisa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lanaperisa/32/4555_2.png) [@lanaperisa](https://discourse.julialang.org/u/lanaperisa)\
**Post date:** [May 15, 2017, 2:03pm UTC](https://discourse.julialang.org/t/gadfly-plot-with-several-graphs-suitable-for-publications/3718/1 "2017-05-15T14:03:20Z")

</div>

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.

```julia
  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.  
 ![](https://global.discourse-cdn.com/julialang/original/3X/e/5/e5ccbd5faf4385f3bb99cdd6fde1a960fbd5398a.png)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 15, 2017, 2:05pm UTC](https://discourse.julialang.org/t/gadfly-plot-with-several-graphs-suitable-for-publications/3718/2 "2017-05-15T14:05:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lanaperisa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lanaperisa/32/4555_2.png) [@lanaperisa](https://discourse.julialang.org/u/lanaperisa)\
**Post date:** [May 15, 2017, 5:58pm UTC](https://discourse.julialang.org/t/gadfly-plot-with-several-graphs-suitable-for-publications/3718/3 "2017-05-15T17:58:54Z")

</div>

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