1
I have the following data 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 view of all graphics on the same page (the size greatly reduces). So I need help from "more experienced" users to improve the code to control the number of charts that are printed per page. For example, if we have 10 subjects and if we want to print two graphs per page then we have a total of 5 pages with 2 graphs per page. I’ve seen a lot in stackoverflow in English but I recognize that I found none so trivial. Is this possible to be done in an elegant way with few command lines?
Thank you very much and all help will be very welcome.
It would be interesting to provide at least a non-trivial part of your data set via output command
dput
. This will make life a lot easier for those who want to help you solve this problem.– Marcus Nunes