Grouped line chart using averages


I'm relatively new to R and stuck here. I'm trying to make a line chart using something like the following:

  patient_id  wk_1  wk_2  wk_3  wk_4 trt_group
       <dbl> <dbl> <dbl> <dbl> <dbl>     <dbl>
1          1    67    78    34    34         0
2          2    34    54    87    56         1
3          3    45    56    67    88         1
4          4    76    77    79    80         0
5          5    67    66    45    44         0

Where wk_1, 2, 3, 4 represent test scores taken at 4 timepoints, and trt_group represents whether or not the patient recieved the drug.

I need my line graph to look like this:

x axis = the timepoints, so week 1 followed by week 2, etc.
y axis = the average score for that time point
grouped by trt_group, so 2 different lines

I know it should be relatively simple using mutate() and then setting up the plot with ggplot(), but I'm having a serious brain fart.

If anybody could point me in the right direction, it would be much appreciated!

What code have you tried? You'll want to pivot_longer() then create your plot.

A reproducible example would be useful too:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.