Skip to content

Commit 64f3d58

Browse files
committed
correct scatterpath + add linearfit
correct scatterpath so that color does not change (see #1495). Add linearfit.
1 parent 1ceb3a5 commit 64f3d58

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/recipes.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,51 @@ end
161161
# path and scatter
162162

163163
# create a path from steps
164+
# see https://github.com/JuliaPlots/Plots.jl/issues/1495
164165
@recipe function f(::Type{Val{:scatterpath}}, x, y, z)
165166
x := x
166167
y := y
167168
seriestype := :scatter
169+
@series begin
170+
()
171+
end
168172
@series begin
169173
seriestype := :path
170174
label := ""
171175
primary := false
172176
()
173177
end
178+
primary := false
174179
()
175180
end
176181
@deps scatterpath path scatter
177182

183+
184+
# ---------------------------------------------------------------------------
185+
# regression line and scatter
186+
187+
# plots line corresponding to linear regression of y on a constant and x
188+
@recipe function f(::Type{Val{:linearfit}}, x, y, z)
189+
seriestype := :scatter
190+
x := x
191+
y := y
192+
@series begin
193+
()
194+
end
195+
X = hcat(ones(length(x)), x)
196+
yhat = X * (X'X \ X'y)
197+
@series begin
198+
y := yhat
199+
seriestype := :path
200+
label := ""
201+
primary := false
202+
()
203+
end
204+
primary := false
205+
()
206+
end
207+
208+
178209
@specialize
179210

180211

0 commit comments

Comments
 (0)