I have data from a clinical trial indexed by Patient no. and treatment group in a data frame. The variables X1 through X7 correspond to observations taken on months 1 through 7. In general an improvement corresponds to a reduction in the measured parameter.
Patient.No Group X1 X2 X3 X4 X5 X6 X7
1 PX-002 1 2 24 4 82 2 2 2
2 PX-009 5 77 6 36 33 1 2 0
3 PX-019 1 6 7 5 4 3 2 2
....
8 PX-001 54 7 7 5 5 3 2 1
9 PX-004 2 67 3 2 3 2 1 1
10 PX-013 3 5 24 4 2 1 1 2
11 PX-015 2 9 4 33 63 2 1 1
What's a good way to plot for say group-1 as separate time series one tracking for each patients evolution over 7 months. With months on the x axis?
This is an ugly prototype of what I mean:
I can do it manually but seems to clunky. Any better ways?
plot(unlist(data[data$Patient.No=="PX-002",c("X1","X2","X3","X4","X5","X6","X7")]),type="b")
lines(unlist(data[data$Patient.No=="PX-019",c("X1","X2","X3","X4","X5","X6","X7")]),type="b")
Or
grp1_data<-data[data$Treat..Group==1,]
plot.ts(y = unlist(grp1_data[grp1_data$Patient.No=="PX-002",c("X1","X2","X3","X4","X5","X6","X7")]),x = c(1,2,3,4,5,6,7))