I was wondering if anyone could assist with code below. I have a huge dataset (> 1000 subjects) which I'm trying to visualise individually.
I was fortunate to find a code written by Tony Cookson from R-bloggers which I've modified for my use. The code works ok but the pdfs produced are damaged-essentially they refuse to open. I have a feeling there's bug somewhere but I haven't yet figured out where. Any assistance would be highly appreciated.
library(lattice)
names = LETTERS[1:3]
for(i in 1:3){
mypath <- file.path("myFilepath", "folder containing 'Plots' subfolder ",
"Plots",paste("myplot_", names[i], ".pdf", sep = ""))
pdf(file=mypath)
mytitle = paste("Theoph Plots", names[i])
xyplot(conc ~ Time | Subject, group = Subject, data = Theoph, type = "l",
layout = c(2, 2), main = mytitle)
dev.off()
}
For the code to be reproducible, you need to replace myFilepath, folder containing 'Plots' subfolder and "Plots" with names of actual folders that can be found on your computer. Please see the original on R-bloggers for more details. I would be very happy to clarify anything that seems ambiguous.
Thanks
Edit:
library(lattice)
names = LETTERS[1:3]
for(i in 1:3){
mypath <- file.path("myFilepath", "folder containing 'Plots' subfolder ",
"Plots",paste("myplot_", names[i], ".pdf", sep = ""))
pdf(file=mypath)
mytitle = paste("Theoph Plots", names[i])
print(xyplot(conc ~ Time | Subject, group = Subject, data = Theoph, type = "l",
layout = c(2, 2), main = mytitle))
dev.off()
}
I've managed to find a temporary solution (above) using the print function. However, I'm currently getting all 12 Subjects in the same pdf. What I really want is 4 subjects (2 by 2 matrix) on separate pdfs so making 3 pdfs in total. Anyone know how to do this?