# plotting – Automatic display of a calculated parameter in the legend of a graphic

I was struggling to find a way to display a value which I constantly change automatically on a graphic. In this case, I want to display
`y=-220.3981+1.0873(CenterDot)x R^2=0.9995`
Basically, I have some data points adjusted to a line (I know the function `NonlinearModelFit` is not the best, but this is only a simplified case of my study and I usually use more farfetched equations)

``````data = {{220, 19.416}, {225, 23.409}, {230, 29.4875}, {235, 35.511}};

Clear(n, m);

CorrelationModelLine = m*x + n;

Korrelierung = NonlinearModelFit(data, {CorrelationModelLine}, {m, n}, x);

FittedData = Table({i, Korrelierung(i)}, {i, 220, 235, 1});

Representation=ListPlot({data,FittedData}, PlotStyle -> {Black, Blue}, PlotRange -> {{195, 247}, All},
PlotLegends ->Placed(SwatchLegend({"Median Feret's diameter", "Fitted model"},
LegendMarkerSize -> 5, LegendMarkers -> {"(FilledCircle)", "(FilledSquare)"},
LegendLabel ->Placed("y=" Korrelierung("RSquared") "   !(*SuperscriptBox((R), (2)))="
Korrelierung("BestFit") "", Above), LabelStyle -> Directive(Black, 15)), {0.3, 0.15}),
Joined -> {False, True}, PlotMarkers -> {"(FilledSquare)", "."}, PlotStyle -> {Black},
Frame -> True, FrameStyle -> Thickness(0.003), AspectRatio -> 0.8, GridLines -> None, GridLinesStyle -> Automatic,
FrameLabel -> {"Threshold (-)", "Median Ferret Diameter ((Mu)m)"},
LabelStyle -> Directive(Black, 25), ImageSize -> Large, Frame -> {True, True, True, True},
FrameTicks -> {{True, False}, {{220, 225, 230, 235}, False}}, PlotLabel -> Style(Framed("Streptomyces coelicolor")))
``````

My problem is that I cannot correctly associate the part R^2= and y= to its corresponding values, the display just shows both parameters and its corresponding values disordered. Also, the equation appears between brackets, any idea how I can remove them? I have unsuccesfully tried with the command `Flatten`.

Thanks everyone

Posted on Categories Articles