# Is x-axis linking ignored in Algebra of Graphics?

**URL:** https://discourse.julialang.org/t/is-x-axis-linking-ignored-in-algebra-of-graphics/76111
**Category:** Visualization
**Tags:** algebraofgraphics
**Created:** [February 9, 2022, 7:06pm UTC](https://discourse.julialang.org/t/is-x-axis-linking-ignored-in-algebra-of-graphics/76111 "2022-02-09T19:06:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)
#### Post date: [February 9, 2022, 7:06pm UTC](https://discourse.julialang.org/t/is-x-axis-linking-ignored-in-algebra-of-graphics/76111/1 "2022-02-09T19:06:47Z")

</div>

I want to plot a density for different groups that might have very different domains in AoG. My understanding is that in the following the x axes should be independent

```julia
dd = DataFrame(x = [rand(10)..., 10 .+ rand(10)...], c = [repeat('a', 10)..., repeat('b', 10)...])
data(dd) * 
mapping(:x, col = :c) * 
density() |> plt -> draw(plt, facet = (;linkxaxes = :none))

```

However I get the following

 ![testfig](https://global.discourse-cdn.com/julialang/original/3X/5/6/562e62e04279474a093d8063ebff0a08b8e1a2c6.png)

Am I misunderstanding something or is there a bug?

Just to be sure

```julia
julia> combine(groupby(dd, :c), :x => extrema)
2×2 DataFrame
 Row │ c x_extrema             
     │ Char Tuple…                
─────┼─────────────────────────────
   1 │ a (0.0424785, 0.978699)
   2 │ b (10.0141, 10.9546)

```

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [March 12, 2022, 9:47pm UTC](https://discourse.julialang.org/t/is-x-axis-linking-ignored-in-algebra-of-graphics/76111/2 "2022-03-12T21:47:09Z")

</div>

The axes are technically not linked (for example, in an interactive setting, zooming on one will not zoom on the other), but by default `density` is evaluated on an interval that spans the whole dataset. You can change that by doing

```julia
data(dd) * 
mapping(:x, col = :c) * 
density(datalimits=extrema) |> plt -> draw(plt, facet = (;linkxaxes = :none))

```

In general, `datalimits` can take any function of the data (data comes in, tuple of values goes out), and it will be computed group by group.

---

<div class="post-metadata">

### Author: ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)
#### Post date: [March 15, 2022, 7:42pm UTC](https://discourse.julialang.org/t/is-x-axis-linking-ignored-in-algebra-of-graphics/76111/3 "2022-03-15T19:42:40Z")

</div>

Thanks that makes sense!
