Trying to add a legend when using CombinePlots

My notebook contains two functions makePlot1 and makePlot2. Which one is used depends on the setting of a variable cMethod. makePlot1 has a single Plot command which plots two data series and I use the following to add a legend to the plot:

cPlotLegends -> 
 Placed[LineLegend[{legend1, legend2}, 
   LegendFunction -> (Framed[#, FrameMargins -> -2, 
       Background -> White, FrameStyle -> Directive[Black]] &), 
   LegendLayout -> "Row", LegendMarkerSize -> {{8, 8}}, 
   LabelStyle -> {FontSize -> 10}], {Right, Bottom}]

This works beautifully and produces a legend looking like this

Legend.png

A screenshot of the full plot from makePlot1 is attached (FullPlot.png)

makePlot2 uses CombinePlots to combine two plots and various “decorations” to fine-tune the results. I have tried adding legends to the two plots before combining them, and have also tried adding a legend after the two plots have been combined. If any kind soul would be prepared to take a look at this, I would be very grateful. My notebook and required data (Dissociation constants.TXT) are attached.

I should add that makePlot1 was only intended to be an interim solution and that makePlot2 is what I want finally..

Dissociation constants.txt (14.4 KB)


V19 Calculation_of_pH_from_known_values_of_Vb.nb (312 KB)

Hi Paul,

I have not looked at the code in the attached notebook, however, this works fine.

ResourceFunction["CombinePlots"][
 Plot[Sin[x], {x, 0, 2 \[Pi]}, 
  PlotLegends -> 
   Placed[LineLegend[{Red, Blue}, {"Sin[x]", "Cos[x]"}, 
     LegendFunction -> (Framed[#, FrameMargins -> -2, 
         FrameStyle -> Directive[Black]] &), LegendLayout -> "Row",
     LegendMarkerSize -> {{8, 8}},
     LabelStyle -> {FontSize -> 10}], {Right, Bottom}], 
  PlotStyle -> Blue],
 Plot[Cos[x], {x, 0, 2 \[Pi]}, PlotStyle -> Red],
 Frame -> True]

Thank you very much, Rohit. Following your example I now have it working just fine and I am attaching the revised, working notebook (the previously uploaded notebook actually contained two typos which would have prevented it from working properly under certain circumstances).

V19WC Calculation_of_pH_from_known_values_of_Vb _OP_1_CP_.nb (314 KB)