Plot Combination

There are four types of plots in Coefplots.jl: Coefplot, MultiCoefplot, GroupedCoefplot, GroupedMultiCoefplot.

MultiCoefplot

We continue the example in quick start. We have also ready seen MultiCoefplot() in the previous chapter.

m = MultiCoefplot(coefplots_withfe, coefplots_pool; title = Label(content="My combined Coefplots"),
                                                    xlabel = Label(content="Regressor Names"),
                                                    ylabel = Label(content="Coefficients"),
                                                    note = Note(content="This is my note."))

m_plot = plot(m)
┌ Error: PGFPlotsX.MissingExternalProgramError("No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.")
└ @ Main string:8

[.pdf], [generated .tex]

GroupedCoefplot

We also provide method GroupedCoefplot() to plot Coefplot objects side by side

g = GroupedCoefplot("OLS" => coefplots_pool, "FE" => coefplots_withfe;
    title = Label(content="My combined Coefplots"),
    ylabel = Label(content="Coefficients"),
    width = 350)

g_plot = plot(g)
┌ Error: PGFPlotsX.MissingExternalProgramError("No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.")
└ @ Main string:8

[.pdf], [generated .tex]

Not limited to plot multiple regressions, GroupedCoefplot() can also divide the coefficients in a single regression into multiple groups however the user wants. To make this happen, we first extract the regression results in DataFrame form,

df = deepcopy(coefplots_pool.data) # extract the regression results from Coefplot object
df
3×4 DataFrame
Rowvarnamebsedof
StringFloat64Float64Float64
1SepalWidth0.6508370.0666474146.0
2PetalLength0.7091320.0567193146.0
3PetalWidth-0.5564830.127548146.0

we add our categorization (it doesn't have to be called coefgroup), use DataFrames.jl's groupby() to produce a GroupedDataFrame, and then plug it in our GroupedCoefplot() method.

df.coefgroup = ["Width Related", "Length Related", "Width Related"]
grouped_df = groupby(df, [:coefgroup])
g2 = GroupedCoefplot(grouped_df; title = Label(content="My combined Coefplots"),
                                 ylabel = Label(content="Coefficients"),
                                 width = 200)

g2_plot = plot(g2)
┌ Error: PGFPlotsX.MissingExternalProgramError("No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.")
└ @ Main string:8

[.pdf], [generated .tex]

GroupedMultiCoefplot

This type is reserved for scenarios when the user wants to have side-by-side plots and also overlapping plots. One can achieve this by plug in Pair{Any, MultiCoefplot} ... or Pair{Any, GroupedCoefplots} ... when invoking GroupedMultiCoefplot(). For example,

df = deepcopy(coefplots_withfe.data)
df.coefgroup = ["Width Related", "Length Related", "Width Related"]
grouped_df = groupby(df, [:coefgroup])
g3 = GroupedCoefplot(grouped_df)

gmc = GroupedMultiCoefplot("OLS" => g2, "FE" => g3; show_legend=[false, true], # which subplot should show their legend
                                                    legend = Coefplots.Legend(at=(0.98,0.02),
                                                                              anchor = Symbol("south east")))

gmc_plot = plot(gmc)
┌ Error: PGFPlotsX.MissingExternalProgramError("No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.")
└ @ Main string:8

[.pdf], [generated .tex]