I am trying to create a line graph which shows the pre and post scores of a questionnaire after an intervention. I am struggling as I want to have the each participant's score pre and post. There is 7 participants so I wanted to have the participants as the 'x' axis and the scores on 'y'. Does anyone know how to do this? I am very unfamiliar with R so unsure on where to even start. I hope the image makes sense for what I am trying to create lol enter image description hereenter image description here
CodePudding user response:
tidy solution:
set.seed(1)
df <- data.frame(participant = LETTERS[1:7],pre_score = runif(7,40,90),post_score = runif(7,60,100))
library(dplyr)
library(tidyr)
library(ggplot2)
df %>%
pivot_longer(-participant, names_to = "intervention", values_to = "score") %>%
ggplot(.,aes(x=participant,y=score,group=intervention,color=intervention))
geom_line()