I have the following date frame (df):
Subject Period Treatment Time Concentration
1 1 1 A -1.000 0.000
2 1 1 A -0.500 0.000
3 1 1 A -0.250 0.000
4 1 1 A 0.000 0.000
5 1 1 A 0.167 1.147
6 1 1 A 0.333 4.993
7 1 1 A 0.500 4.324
8 1 1 A 0.667 6.623
9 1 1 A 0.833 4.945
10 1 1 A 1.000 3.446
11 1 1 A 1.250 2.280
12 1 1 A 1.500 2.796
13 1 1 A 1.750 1.666
14 1 1 A 2.000 1.105
15 1 2 B -1.000 0.000
16 1 2 B -0.500 0.000
17 1 2 B -0.250 0.000
18 1 2 B 0.000 0.000
19 1 2 B 0.167 2.378
20 1 2 B 0.333 24.137
21 1 2 B 0.500 22.876
22 1 2 B 0.667 25.779
23 1 2 B 0.833 27.178
24 1 2 B 1.000 19.609
25 1 2 B 1.250 13.392
26 1 2 B 1.500 10.431
27 1 2 B 1.750 7.402
28 1 2 B 2.000 6.793
29 2 1 B -1.000 0.000
30 2 1 B -0.500 0.000
31 2 1 B -0.250 0.000
32 2 1 B 0.000 0.000
33 2 1 B 0.167 0.097
This data frame may contain N subjects with M concentration curves per subject (which will depend on the number of treatments).
To generate the graphs of plasma concentration of each subject I am using the following code:
p<- ggplot(Data, aes(x=Time, y=Concentration, group=Subject:Treatment:Period, shape=Treatment:Period, color=Treatment)) +
geom_line() + geom_point(size=3) + facet_wrap(~ Subject,ncol = 2)+ scale_shape_manual(values=c(7,7,1,1)) + scale_colour_manual(values=c("red","darkblue"))+ xlab("Time (hr)")+
ylab("Concentration (ng/mL)") + ggtitle("Individual Plasma Concentration - Drug X")
My problem is that when the number of subjects is large it is practically impossible to have a good visualization of all the graphics on the same page (the size reduces a lot). So I need help from "savvy" users to hone code to control the number of graphics that are printed per page. For example, if we have 10 subjects and if we want to print two graphics per page then we will have a total of 5 pages with 2 graphics per page. I've seen a lot on stackoverflow in English, but I recognize that I found none so trivial. Is it possible to do this in an elegant way with a few command lines?
Thank you very much and all your help will be very welcome.