Is this what you're aiming for?
library(tidyverse)
dat = tribble(
~PID, ~session, ~Craving_value, ~Measurement,
1, 1, 2 ,"Craving1",
1, 2, 100 ,"Craving2",
1, 3, 62 ,"Craving3",
1, 4, 46 ,"Craving4",
1, 5, 61 ,"Craving5",
1, 6, 98 ,"Craving6",
1, 7, 50 ,"Craving7",
2, 1, 41 ,"Craving1",
2, 2, 85 ,"Craving2",
2, 3, 28 ,"Craving3",
2, 4, 99 ,"Craving4",
2, 5, 23 ,"Craving5",
2, 6, 92 ,"Craving6",
2, 7, 72 ,"Craving7",
3, 1, 34 ,"Craving1",
3, 2, 43 ,"Craving2",
3, 3, 73 ,"Craving3",
3, 4, 48 ,"Craving4",
3, 5, 40 ,"Craving5",
3, 6, NA ,"Craving6",
3, 7, NA ,"Craving7",
4, 1, 22 ,"Craving1",
4, 2, 72 ,"Craving2",
4, 3, 86 ,"Craving3",
4, 4, 80 ,"Craving4",
4, 5, 16 ,"Craving5",
4, 6, 40 ,"Craving6",
4, 7, 21 ,"Craving7")
dat %>%
group_by(PID) %>%
mutate(mean_val = mean(Craving_value, na.rm = T)) %>%
ggplot(aes(x = session, y = Craving_value)) +
geom_point() +
geom_hline(aes(yintercept = mean_val)) +
stat_summary(
aes(y = Craving_value),
fun = mean,
colour = "red",
geom = "line"
) +
facet_wrap( ~ PID) +
theme_classic()
#> Warning: Removed 2 rows containing non-finite values (stat_summary).
#> Warning: Removed 2 rows containing missing values (geom_point).