I have a plot that requires a lot of code to create protrusions. So, it would be nice to just replace the data layer of the plot without messing with the protrusions. Is this possible?
I have example code here:
using DataFrames, CairoMakie, AlgebraOfGraphics,
CairoMakie.activate!(type = "svg") # crisper plots than default png
set_aog_theme!() # color-blind friendly colors
update_theme!(fontsize = 20) # larger font size
## create two points to plot
df = DataFrame(x = [0.9,0.8], y = [0.9,0.8])
## plot two points
dfMapping = mapping(:x, :y) *
visual(color = :darkblue,
markersize = 24)
dfLayer = data(df) * dfMapping
draw(dfLayer, axis = (limits = (0,1,0,1),))
## create protrusions
topDF = DataFrame(x = 0:0.001:1,
y = 0:0.001:1)
rightDF = DataFrame(x = 0:0.001:1,
y = 1:-0.001:0)
topLayer = data(topDF) * mapping(:x,:y) * visual(Lines)
rightLayer = data(rightDF) * mapping(:x,:y) * visual(Lines)
## create empty canvas to plot into
marginPlot = Figure()
draw!(marginPlot[1,1],dfLayer, axis = (limits = (0,1,0,1),))
## place protrusions in figure 1
rightMarginAxis = Axis(marginPlot[1,1, Right()],
width = 100,
limits = (nothing,(0,1)))
topMarginAxis = Axis(marginPlot[1,1, Top()],
height = 100,
limits = ((0,1),nothing))
hidedecorations!(rightMarginAxis)
hidespines!(rightMarginAxis)
hidedecorations!(topMarginAxis)
hidespines!(topMarginAxis)
draw!(rightMarginAxis, topLayer)
draw!(topMarginAxis, rightLayer)
marginPlot
## update data
push!(df, [0.2,0.2])
## update plot layer
dfLayer = data(df) * dfMapping
## update marginPlot
draw!(marginPlot[1,1],dfLayer, axis = (limits = (0,1,0,1),))
marginPlot
## can I now keep protrusions and axes, but plot only new data
newDF = DataFrame(x = 0.5, y = 0.5)
newLayer = data(newDF) * dfMapping * visual(Scatter, color = :darkorange)
draw!(marginPlot[1,1], newLayer, axis = (limits = (0,1,0,1),))
marginPlot
## in other words, how to remove the blue dots from pic?
delete!(marginPlot[1,1]) ## gives method error
which generates the following plot:
BUT, what I really want is just the orange dot and not the blue dots. How would I do this? Thx!