# Link axis not working in Plots for marginal density

**URL:** https://discourse.julialang.org/t/link-axis-not-working-in-plots-for-marginal-density/76857
**Category:** Visualization
**Created:** [February 21, 2022, 7:04pm UTC](https://discourse.julialang.org/t/link-axis-not-working-in-plots-for-marginal-density/76857 "2022-02-21T19:04:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rwalters31](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rwalters31/32/25594_2.png) [@rwalters31](https://discourse.julialang.org/u/rwalters31)
#### Post date: [February 21, 2022, 7:04pm UTC](https://discourse.julialang.org/t/link-axis-not-working-in-plots-for-marginal-density/76857/1 "2022-02-21T19:04:52Z")

</div>

![DeckLandingPositionPlot](https://global.discourse-cdn.com/julialang/original/3X/b/2/b2c24473efc6cce2bfa869ad43dadf4877f69235.png)

I’m trying to put in marginal density plots above and to the right of x,y scatter data.

I have tried the ‘link’ in both the :x, :y, and :both directions but as you can see the top figure does not match the axis of the bottom figure.

```julia
using Plots, StatsPlots, KernelDensity, DataFrames, Images,Plots.PlotMeasures
topdensity = @df finalDeckLocation density(:POSYI,group = :subject,xlim=[left2center,center2right])
sidedensity = plot(ky.density,ky.x; ylim=[(center2top-top2bottom),center2top])
Plots.plot([left2center,center2right],
	[(center2top-top2bottom),
	center2top],reverse(img, dims = 1),
 	yflip = false,
  	aspect_ratio = 1,
  	xlim=[left2center,center2right],
  	ylim=[(center2top-top2bottom),center2top],
  	left_margin = [20mm 0mm],
   	bottom_margin = 10mm);
deckfinalposplot = @df @subset(finalDeckLocation, :subject .<=3) scatter!(
	:POSYI,
	(:SHIPXI .-:POSXI.-174).*-1,
	xlim=[left2center,center2right],
	ylim=[(center2top-top2bottom),center2top],
	group = :iteration,
	markercolor = :subject,
	markersize = 2,
	alpha = 0.5,
	legend = :none,
	dpi=300)

layout = @layout [
    topdensity _
    deckfinalposplot{0.8w, 0.8h} sidedensity
]

plot(topdensity, deckfinalposplot, sidedensity; layout, link = :x, dpi = 300)

```
