Dear all,
I am new to Julia and AoG - coming from the Tidyverse and ggplot… - and don’t (even) manage to add an x=y line to a scatter plot:
using AlgebraOfGraphics, CairoMakie, Statistics
x=rand(4)
y = x .+ 0.2 .+ 0.2randn(4)
lab = string.(1:4)
p = data((;x, y, lab)) * mapping(:x, :y, color=:lab)
# This draws the "data"
draw(p, axis=(aspect=1, limits=((-0.2,1.4),(-0.2,1.4))))
# This would be my naive guess to include the abline
draw(p + visual(ABLines, slope=1.0, intercept=0.0), axis=(aspect=1, limits=((-0.2,1.4),(-0.2,1.4))))
# Thought I need to bind it better to the plot, but (of course) it interprets every x,y as slope, intercept...
draw(p + p * visual(ABLines, linestyle=:dash, linewidth=5), axis=(aspect=1, limits=((-0.2,1.4),(-0.2,1.4))))
# Create a new dataset (would be cumbersome for this simple task, but also does not work)
p2 = data((;slope=[1.], intercept=[0.0])) * visual(ABLines, linestyle=:dash, linewidth=5)
p + p2; ### Ok
draw(p+p2; axis=(aspect=1,xticks=0:0.2:1.4, yticks=0:0.2:1.4, limits=((0,1.4),(0,1.4))))
The error I get is: ## ERROR: MethodError: no method matching combine_axes().
Something like this works, but is a horrible workaround (and does not plot just one segment of course):
p3 = data((;x, y, lab)) * mapping((:x, :y) => ((t1,t2) -> mean([t1,t2])), (:x, :y) => ((t1, t2) -> mean([t1, t2])) ) * visual(Lines, color=:red, linestyle=:dot)
draw(p+p3; axis=(aspect=1,xticks=0:0.2:1.4, yticks=0:0.2:1.4, limits=((0,1.4),(0,1.4))))
Thanks in advance for helping me not give up…