I am able to plot several plots that do get plotted in a lattice format with my code. However, there are several of these plots, 77 to be exact so, each plot is totally squished and unreadable. I have tried playing with the width, height, facet_wrap_paginate as well but none seem to give me the output I want. Each plot is a line plot for each subject and EVTEST and there are 77 subjects. I want to break the plots in multiple panels of 4X3 or 4X4 and also pages. Also I am outputting it in RTF. I am open to outputting in PDF as well if it works.How do I do it?
Below is a fictitious data, which is the same format that I use as input in my code. what I am trying to plot is line plots for this longitudinal data, where my X axis is VISITDY_D and Y axis is EVSTRESN. I am grouping the plots by creating a concatenated handle (SUBJID_EVTEST_SITE).
SUBJID SITE EVTEST EVSTRESN VISITDY_D SIDE
1 AB ABC 1.1 D00 Left
1 AB ABC 2.1 D28 Right
1 AB ABC 2.2 D56 Left
1 AB ABC 2.3 D84 Left
2 AB ABC 1.5 D00
2 AB ABC 1.6 D28 Right
#read the data (csv file)
donnees <- read.csv(paste0(path_data,"Sample.csv"), sep = ";",header =
T,stringsAsFactors = FALSE)
Params = c("Phenotype1","Phenotype2")
#PLOTTING FUNCTION
pf1<-function(subD,tit1){ # subD:Input data, tit1: Title for the plot
subD$SUBJID1 <-
as.factor(paste0(subD$RANDOID,'_',subD$EVTEST,'_',subD$SITE))
p1 <- ggplot(subD,aes(x = VISITDY_D,y = EVSTRESN, color=SIDE,group=SIDE))
geom_line(position=position_dodge(width=0.7))+
geom_point() + facet_wrap_paginate(~ SUBJID1, nrow=3,ncol=3,page=1) +
theme()
print(p1)
p1 <- ggplot(subD,aes(x = VISITDY_D,y = EVSTRESN,
color=SIDE,group=SIDE)) +
geom_line(position=position_dodge(width=0.7))+
geom_point() + facet_wrap(~ SUBJID1) + theme()
print(p1)
}
# OUTPUT; Calling the plotting function in RTF
oP <- /output_directory
setwd(oP)
rtf <- RTF(file = paste0("TEST_","individual profiles.rtf"))
addTOC(rtf)
addPageBreak(rtf)
for(s in 1:length(Params)){
dat = subset(donnees,donnees$EVTEST %in% Params[s])
SUBJID1 <-as.factor(paste0(dat$RANDOID,'_',dat$EVTEST,'_',dat$SITE))
tit1<-paste0(Params[s])
addHeader(rtf,tit1,font.size = 4, TOC.level = 1)
addPlot(rtf, plot.fun=pf1, subD= dat,tit1= tit1, width= 7, height=5.2,
res=250)
}
done(rtf)