Hello people,
I’m trying to plot longitudinal data that includes columns “ID”, “Time” and “Weight”. When I try to plot it with command plot(df.Time, df.Weight) it creates one line that goes back and forth. So how I can split the legends by ID?
Example image with zigzag lines:
Here is code to generate the problem:
using DataFrames
using Random
using Statistics
using Distributions
using Plots
n = 50
left_ratio = 5; right_ratio = convert(Int, n * 1/left_ratio)
ID = repeat(1:right_ratio,inner=left_ratio)
Time = repeat(1:left_ratio, outer=right_ratio)
beta0 = 5; beta1 = 2
error = 10
b0_random_effect_variance= 10
b0_random_effect = repeat(rand(Normal(0, sqrt(b0_random_effect_variance)),right_ratio),inner=left_ratio)
y = (beta0 .+ b0_random_effect) .+ (beta1 .* Time) .+ rand(Normal(0, sqrt(error)), n)
full_df = DataFrame(ID=ID, Time=Time, Weight=y)
plot(full_df.Time, full_df.Weight)