TransWikia.com

How to create a modified line plot?

Mathematica Asked by Tom De Vries on February 4, 2021

I am looking for help to create a Line Plot that looks something like the image below.
Line Plot Image

The NumberLinePlot function works well if you have a sets of distinct values, but this plot would create stacks of common values as shown. I tried all the "data visualization" help files, but unless I missed an option, didn’t find anything that would help to make this happen.

Sample data is below, hoping to stack on "tenths"

data = {5.1, 7.3, 6.9, 4.7, 5.0, 6.2, 6.4, 5.5, 5.7, 6.8, 6.0, 4.8, 4.1, 
5.2, 8.1, 6.3, 7.5, 5.0, 5.7, 8.2, 3.3, 3.1, 4.3, 5.9, 6.6, 5.8, 6.4, 
6.1, 4.6, 5.7}

2 Answers

One way to do this is the following:

data = {5.1, 7.3, 6.9, 4.7, 5.0, 6.2, 6.4, 5.5, 5.7, 6.8, 6.0, 4.8, 
   4.1, 5.2, 8.1, 6.3, 7.5, 5.0, 5.7, 8.2, 3.3, 3.1, 4.3, 5.9, 6.6, 
   5.8, 6.4, 6.1, 4.6, 5.7};
lsPoints =
  GroupBy[Round[data], Identity];
lsPoints = KeyValueMap[Thread[{#1, Range[Length[#2]]}] &, lsPoints];

ListPlot[lsPoints, Axes -> {True, False}, PlotStyle -> Directive[{PointSize[0.02], ColorData["Rainbow", 0.28]}]]

(data is with the sample data from the question.)

enter image description here

Answered by Anton Antonov on February 4, 2021

gathered = Gather @ Sort @ Round @ data;

NumberLinePlot

nlpdata = Join[## & @@ Map[List, gathered, {-1}], 2];

NumberLinePlot[nlpdata, 
 PlotStyle -> Directive[AbsolutePointSize[10], ColorData[97]@1]]

enter image description here

Histogram + ChartLayout

Histogram[nlpdata, {1},
  ChartStyle -> ColorData[97]@1, Axes -> {True, False}, 
  ChartLayout -> "Stacked", PerformanceGoal -> "Speed"] /. 
 Rectangle[a_, b_, ___] :> Disk[Mean[{a, b}], Offset[7]]

enter image description here

Histogram + ChartElements

Histogram[Round@data, {1}, 
 ChartElements -> {Graphics[Disk[{0, 0}, Offset[7]]], {All, 1}}, 
 Axes -> {True, False}]

enter image description here

ListPlot

ListPlot[MapIndexed[Thread[{#, #2[[1]]}] &] /@ gathered, 
 PlotStyle -> Directive[AbsolutePointSize[10], ColorData[97]@1], 
 AspectRatio -> 1/2,
 Axes -> {True, False}, 
 PlotRange -> {{1, 9}, All}, 
 Ticks -> {Range @ 9, None}]

enter image description here

BubbleChart

BubbleChart[{#, #2, #2} & @@@ Tally[Round@data], 
  BubbleSizes -> {.07, .07}, 
  Frame -> {{False, False}, {True, False}},
  PlotRange -> {Automatic, {1, All}}] /. 
 Disk[{a_, b_}, c_] :> (Disk[{a, #}, c] & /@ Range[b])

enter image description here

Graphics

Graphics[{AbsolutePointSize[15], ColorData[97]@1, 
  Point[Join @@ (Thread[{#, Range @ #2}] & @@@ Tally[Round @ data])]}, 
 AspectRatio -> 1, Axes -> {True, False}, 
 AxesOrigin -> {Automatic, 0}, 
 PlotRangePadding -> {{1, 1}/2, Automatic}]

enter image description here

Answered by kglr on February 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP