I would like to create a line graph where I have a single colored line but where points have a different color depending on a variable in the dataset (demonstrating LOCF model as part of project). I have attached my code & its corresponding output below:
suppressPackageStartupMessages(library(mice))
suppressPackageStartupMessages(library(tidyverse))
airquality_indicator <- airquality %>%
mutate(imputation_indicator = if_else(is.na(Ozone), "imputed", "observed"))
airquality2 <- tidyr::fill(airquality_indicator, Ozone)
head(airquality2, 30) %>% ggplot(aes(x = Day,y= Ozone, color = imputation_indicator)) +
geom_line() +
geom_point() +
labs(y = "ozone (ppb)",
x = "Day Number")
Meanwhile, here is the desired output:
Thank you!