Skip to content

Commit fd4fa85

Browse files
authored
Merge pull request #493 from LibraChris/lollipop_chart
Add Chart.Residual – Modified Lollipop Chart Implementation
2 parents c93e06d + d6235fd commit fd4fa85

File tree

3 files changed

+611
-1
lines changed

3 files changed

+611
-1
lines changed

Plotly.NET.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04_distribution-charts", "0
140140
docs\distribution-charts\point-density.fsx = docs\distribution-charts\point-density.fsx
141141
docs\distribution-charts\splom.fsx = docs\distribution-charts\splom.fsx
142142
docs\distribution-charts\violin-plots.fsx = docs\distribution-charts\violin-plots.fsx
143+
docs\distribution-charts\residual.fsx = docs\distribution-charts\residual.fsx
143144
EndProjectSection
144145
EndProject
145146
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01_chart-layout", "01_chart-layout", "{C7D0EF67-9A18-49DD-AC79-944E384BD8D0}"

docs/distribution-charts/residual.fsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb)&emsp;
31+
[![Notebook]({{root}}img/badge-notebook.svg)]({{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

Comments
 (0)