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.
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}
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.)
Answered by Anton Antonov on February 4, 2021
gathered = Gather @ Sort @ Round @ data;
nlpdata = Join[## & @@ Map[List, gathered, {-1}], 2];
NumberLinePlot[nlpdata,
PlotStyle -> Directive[AbsolutePointSize[10], ColorData[97]@1]]
Histogram[nlpdata, {1},
ChartStyle -> ColorData[97]@1, Axes -> {True, False},
ChartLayout -> "Stacked", PerformanceGoal -> "Speed"] /.
Rectangle[a_, b_, ___] :> Disk[Mean[{a, b}], Offset[7]]
Histogram[Round@data, {1},
ChartElements -> {Graphics[Disk[{0, 0}, Offset[7]]], {All, 1}},
Axes -> {True, False}]
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}]
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])
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}]
Answered by kglr on February 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP