is it possible to have a the legend for marker and line overlay on top each other if they follow the same color as in the code and figure below.
I am still not sure exactly on the thinking behind creating the legend from a mapped variable in the dataset. If some one can explain in more detail, I would appreciate it.
dd = DataFrame(id = [1,1,1,1,1,2,2,2,2,2],
time = [10,20, 30, 40, 50, 10,20, 30, 40, 50],
dv = [5.0, 4.0, 3.0, 2.0, 1.0,10.0, 9.0, 8.0, 7.0, 6.0],
dv2 = [5.0, 4.0, 3.0, 2.0, missing,10.0, 9.0, 8.0, 7.0, missing])
dd[!, :dv2] = coalesce.(dd[!, :dv2], NaN)
palette = ColorSchemes.tab10.colors
color_indices = groupindices(groupby(dd, :id))
fig = Figure(resolution = (1000, 700))
ax1 = fig[1, 1] = Axis(fig,
title = "",
xlabel="Time (min)",
ylabel="Concentration (μg/L)")
scatter!(ax1,
dd[!,:time], dd[!,:dv2],
color=palette[color_indices])
lines!(ax1,
dd[!,:time], dd[!,:dv2],
color=palette[color_indices])
fig
basically I want he the legend to be like this (generated by ggplot2 below)
dd = data.frame(id = c(1,1,1,1,1,2,2,2,2,2),
time = c(10,20, 30, 40, 50, 10,20, 30, 40, 50),
dv = c(5.0, 4.0, 3.0, 2.0, 1.0,10.0, 9.0, 8.0, 7.0, 6.0),
dv2 = c(5.0, 4.0, 3.0, 2.0, NA,10.0, 9.0, 8.0, 7.0, NA))
dd %>%
ggplot(aes(x = time, y = dv2,color=factor(id)))+
geom_point() + geom_line()