/
recipes.jl
41 lines (36 loc) · 1.43 KB
/
recipes.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#-----------------------------------------------------------------# partitionplot
@userplot struct PartitionPlot
args
end
@recipe function f(o::PartitionPlot; nparts=100, stat=Extrema(), by=nothing, dropmissing=false)
t = o.args[1]
sel = map(x -> lowerselection(t, x), o.args[2:end])
# Create the (Indexed)Partition object
o = if length(sel) == 1
Partition(stat, nparts)
elseif length(sel) == 2
T = typeof(collect(rows(t)[1])[sel[1]]) # Type of first selection
IndexedPartition(T, stat, nparts)
else
throw(ArgumentError("too many arguments for partitionplot"))
end
# Wrap the (Indexed)Partition in an FTSeries to possibly remove missing values
s = FTSeries(o; filter = dropmissing ? !IndexedTables._ismissing : x -> true)
if by === nothing
reduce(s, t; select=sel)
else
grp = groupreduce(s, t, by; select=sel)
grp = isa(t, DDataset) ? collect(grp) : grp
for row in rows(grp)
@series begin row[2] end
end
end
end
"""
partitionplot(table, y; stat=Extrema(), nparts=100, by=nothing, dropmissing=false)
partitionplot(table, x, y; stat=Extrema(), nparts=100, by=nothing, dropmissing=false)
Plot a summary of variable `y` against `x` (`1:length(y)` if not specified). Using `nparts`
approximately-equal sections along the x-axis, the data in `y` over each section is
summarized by `stat`.
"""
partitionplot