# ABLines in Algebraofgraphics (x=y line, identity line, 1-to-1 line)

**URL:** <https://discourse.julialang.org/t/ablines-in-algebraofgraphics-x-y-line-identity-line-1-to-1-line/89106>\
**Category:** Visualization\
**Tags:** algebraofgraphics\
**Created:** [October 22, 2022, 1:02pm UTC](https://discourse.julialang.org/t/ablines-in-algebraofgraphics-x-y-line-identity-line-1-to-1-line/89106 "2022-10-22T13:02:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mreichMPI-BGC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mreichmpi-bgc/32/43775_2.png) [@mreichMPI-BGC](https://discourse.julialang.org/u/mreichMPI-BGC)\
**Post date:** [October 22, 2022, 1:02pm UTC](https://discourse.julialang.org/t/ablines-in-algebraofgraphics-x-y-line-identity-line-1-to-1-line/89106/1 "2022-10-22T13:02:54Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 22, 2022, 6:58pm UTC](https://discourse.julialang.org/t/ablines-in-algebraofgraphics-x-y-line-identity-line-1-to-1-line/89106/2 "2022-10-22T18:58:24Z")

</div>

You can specify data in `mapping` already, although I honestly don’t completely grok the logic of that. For example, `mapping(x, y, color = lab)` in the first part, without `data`, doesn’t work.

[https://aog.makie.org/stable/gallery/gallery/data%20manipulations/pre\_grouped\_data/#Pre-grouped-data](https://aog.makie.org/stable/gallery/gallery/data%20manipulations/pre_grouped_data/#Pre-grouped-data)

Anyway, this syntax works if you don’t want to do a second `data` call for the `ABLines`:

```julia
julia> p = data((; x, y, lab)) * mapping(:x, :y, color = :lab) + mapping([0], [1]) * visual(ABLines);

julia> draw(p; axis=(aspect=1,xticks=0:0.2:1.4, yticks=0:0.2:1.4, limits=((0,1.4),(0,1.4))))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d5fe498b079780556b3db2a2458a56656af48082.png)

---

<div class="post-metadata">

**Author:** ![mreichMPI-BGC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mreichmpi-bgc/32/43775_2.png) [@mreichMPI-BGC](https://discourse.julialang.org/u/mreichMPI-BGC)\
**Post date:** [October 22, 2022, 7:39pm UTC](https://discourse.julialang.org/t/ablines-in-algebraofgraphics-x-y-line-identity-line-1-to-1-line/89106/3 "2022-10-22T19:39:28Z")

</div>

Thanks! This works and with defining

```
one2one = mapping([0], [1]) * visual(ABLines, color=:red, linestyle=:dash)

```

beforehand (globally) I can use `p + one2one` , getting closer to ggplot style 😉

I hope some of such convenience wrappers will be developed.
