# (Plots.jl) linked (aligned) x-axis figures with outer legends

**URL:** <https://discourse.julialang.org/t/plots-jl-linked-aligned-x-axis-figures-with-outer-legends/63523>\
**Category:** New to Julia\
**Tags:** plotting, plots\
**Created:** [June 25, 2021, 2:27am UTC](https://discourse.julialang.org/t/plots-jl-linked-aligned-x-axis-figures-with-outer-legends/63523 "2021-06-25T02:27:10Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 25, 2021, 7:09am UTC](https://discourse.julialang.org/t/plots-jl-linked-aligned-x-axis-figures-with-outer-legends/63523/7 "2021-06-25T07:09:04Z")

</div>

FWIW, for the github example linked above, the following workaround produces an equivalent plot, with “outer” legends and axis aligned:

```julia

using Printf, StatsPlots; gr()

d16mer = Dict("Making BioSeq"=> 0.719,
    "Iterating kmers"=> 0.104,
    "Checking sym kmer"=> 0.063,
    "Reading line"=> 0.06,
    "Creating kmer iterator"=> 0.037
    )

dcpg = Dict("Making BioSeq"=> 0.695,
    "Reading line"=> 0.06,
    "GpC detection"=> 0.046,
    "Length of seq"=> 0.032,
    "Indexing seq"=> 0.038
    )

function bp(dict; kw...)
    dict["Misc"] = 1 .- sum(values(dict))
    vals = reverse(collect(values(dict)))'
    labs = permutedims(reverse(collect(keys(dict))))
    groupedbar(vals, label = labs, bar_position = :stack, orientation=:horizontal,yticks = []; kw...)
end

x = LinRange(0,1,5)
xstr = [@sprintf("%.2f", xi) for xi in x]
a = bp(d16mer)
plot!(x, 0*x .+ ylims(a)[1], lc=:black,label=false,widen=false)
xticks!(x, xstr)
b = bp(dcpg)
plot!(x, 0*x .+ ylims(b)[1], lc=:black,label=false,widen=false)
xticks!(x, xstr)
plot(a,b, link=:x,layout=(2,1),xlims=(0,1.7),legend=:topright,showaxis=false)

```

![Plots_gr_linked_vertical_sublplots_outerlegends](https://global.discourse-cdn.com/julialang/original/3X/1/a/1a2bc3454857747944dcc3c7ff4ea6ae38cf89f0.png)

---

_[View the full topic](https://discourse.julialang.org/t/plots-jl-linked-aligned-x-axis-figures-with-outer-legends/63523)._
