I tried to do a faceted plot using Plots.jl
. The code below does almost everything I wanted,
except for one thing: the vertical axes are aligned on each row, but not across rows. The argument
link = :y
in the last Plots.plot
function was supposed to align all vertical axes, but it looks
like it is aligning only the vertical axes in each row.
Note: Alignment depends on the specific random numbers generated. Occasionally all vertical axes do align.
Is there a way to align all vertical axes?
using Plots
dfd = DataFrame(
:Date => [sum([Date(Dates.now()), Dates.Day(i)]) for i in 1:60],
:Return => randn(60) ./ 100.0,
:A => repeat(collect(1:5), inner = 12),
:B => repeat(collect(1:12), inner = 5)
)
gdf = groupby(dfd, [:B])
n_rows = 3
n_cols = div(length(gdf), 3)
p = [
Plots.plot(
gdf[i].Date,
gdf[i].Return,
legend_position = false,
rotation = 45,
title = "B = $i",
titlefontsize = 8,
xtickfontsize = 6,
yticks = i % n_cols == 1,
ytickfontsize = 6) for i in 1:12
]
plt_panel = Plots.plot(
p...,
link=:y,
size = (4000 / 4, 700),
layout = (n_rows, n_cols),
legend = false,
plot_title = "Hello"
)
display(plt_panel)