|
| 1 | +(** |
| 2 | +--- |
| 3 | +title: Residual chart |
| 4 | +category: Distribution Charts |
| 5 | +categoryindex: 5 |
| 6 | +index: 10 |
| 7 | +--- |
| 8 | +*) |
| 9 | + |
| 10 | +(*** hide ***) |
| 11 | + |
| 12 | +(*** condition: prepare ***) |
| 13 | +#r "nuget: Newtonsoft.JSON, 13.0.3" |
| 14 | +#r "nuget: DynamicObj, 7.0.1" |
| 15 | +#r "nuget: Giraffe.ViewEngine.StrongName, 2.0.0-alpha1" |
| 16 | +#r "../../src/Plotly.NET/bin/Release/netstandard2.0/Plotly.NET.dll" |
| 17 | + |
| 18 | +Plotly.NET.Defaults.DefaultDisplayOptions <- |
| 19 | + Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference) |
| 20 | + |
| 21 | +(*** condition: ipynb ***) |
| 22 | +#if IPYNB |
| 23 | +#r "nuget: Plotly.NET, {{fsdocs-package-version}}" |
| 24 | +#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}" |
| 25 | +#endif // IPYNB |
| 26 | + |
| 27 | +(** |
| 28 | +# Residual chart |
| 29 | +
|
| 30 | +[](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb)  |
| 31 | +[]({{root}}{{fsdocs-source-basename}}.ipynb) |
| 32 | +
|
| 33 | +*Summary:* This example shows how to create a Residual (or Lollipop) chart in F#. |
| 34 | +
|
| 35 | +Let's first create some data for the purpose of creating example charts: |
| 36 | +
|
| 37 | +*) |
| 38 | + |
| 39 | +open Plotly.NET |
| 40 | + |
| 41 | +let ydata = |
| 42 | + [9.;25.;-73.;-30.;3.;35.;-35.;9.;-3.;33.;17.;25.;-15.;38.;-2.;36.;29.;-23.;15.;19] |
| 43 | +let mean = Seq.average ydata |
| 44 | + |
| 45 | +let xy = Seq.indexed ydata |
| 46 | + |
| 47 | +(** |
| 48 | +## What is a Residual (Lollipop) Chart? |
| 49 | +
|
| 50 | +A Residual or Lollipop chart is a type of chart that showcases the deviation of values to a reference value, often the **mean**, **median**, or a custom threshold. |
| 51 | +
|
| 52 | +- Each observation is represented by a **dot** connected to the reference line by a **line segment**. |
| 53 | +- This type of visualization is useful for identifying **patterns**, **outliers**, or **distribution skewness** in relation to a central value. |
| 54 | +- This approach is also helpful when visualizing residuals in regression models to assess **SSR (Sum of Squared Residuals)**, or highlight deviations to measures like **R²**. |
| 55 | +*) |
| 56 | + |
| 57 | +let residualChart = |
| 58 | + Chart.Residual( |
| 59 | + xy=xy, |
| 60 | + referenceValue = mean, |
| 61 | + MarkerColor = Color.fromString "purple", |
| 62 | + LineColor = Color.fromString "blue", |
| 63 | + ReferenceColor = Color.fromString "black" |
| 64 | + ) |
| 65 | + |
| 66 | +(*** condition: ipynb ***) |
| 67 | +#if IPYNB |
| 68 | +residualChart |
| 69 | +#endif // IPYNB |
| 70 | + |
| 71 | +(***hide***) |
| 72 | +residualChart |> GenericChart.toChartHTML |
| 73 | +(***include-it-raw***) |
| 74 | + |
0 commit comments