0

I have the below code, which produces 3 combined graphs which have the same participant ids, each representing a different time period. The respondent answers in each time period. I wonder if there is a way to connect the participant ids in each wave to show individual change over time. I have tried many things but can't work it out. Any help would be greatly appreciated.

combined_data$pidp <- as.character(combined_data$pidp)

subset_data_list <- list()


for (wave_val in unique(combined_data$wave)) {
  subset_data_list[[as.character(wave_val)]] <- combined_data[combined_data$wave == wave_val,][1:50,]
}


plot_list <- lapply(names(subset_data_list), function(wave_val) {
  ggplot(subset_data_list[[wave_val]], aes(x = ANNUAL_INCOME, y = GENERAL_HAPPINESS, color = pidp)) +
    geom_line() +
    geom_point(size = 2) +
    labs(x = "Income", y = "Happiness") +
    theme_minimal() +
    ggtitle(paste("Wave", wave_val)) +
   theme(legend.position = "none")  +
    scale_y_continuous(breaks = seq(1, 4, by = 1), limits = c(1, 4)) 
})


combined_plot <- ggpubr::ggarrange(plotlist = plot_list, ncol = 3)


print(combined_plot)
eng
  • 443
  • 1
  • 4
  • 10
Ella
  • 23
  • 3
  • 1
    We don't have your data, so we can't reproduce your plots with the code you have provided. This makes it nearly impossible to test various solutions to help you. Could you make the example reproducible by adding data we can use, such as the output of `dput(combined_data)`? – Allan Cameron Jul 19 '23 at 20:52
  • I think there are few related questions here, like: https://stackoverflow.com/questions/32158374/draw-lines-between-two-different-grid-arranged-plots – Jon Spring Jul 19 '23 at 21:59

0 Answers0