I have a list of 18 items (called allDataTestRetest), for all these 18 items I want to make a plot. I made the following function to make a Bland Altman Plot of my data:
rater = input[,4]
ba.stats <- bland.altman.stats(input[,2], input[,3])
# Create data fram of needed data because ggplot needs to work with a dtaa frame
BlandData = data.frame(ba.stats$means,ba.stats$diffs,rater)
p <- ggplot(BlandData,aes(x=ba.stats.means,y=ba.stats.diffs,colour=factor(rater)))+
geom_point() +
# coord_cartesian(ylim=c(-3,3))+
labs(x="mean day 1 - day 2", y = "difference day 1 - day 2",colour="rater") +
geom_hline(yintercept=ba.stats$lines, size = 1, linetype = c("dashed","dotted","dashed"), color = c("lightblue","blue","lightblue")) +
geom_hline(yintercept = ba.stats$CI.lines, size = 0.7, linetype = "dashed", color = c("lightblue","lightblue","blue","blue","lightblue","lightblue"))
}
Then I used lapply to make such a plot for my complete list
plots <- lapply(allDataTestRetest,func_blandAltmanPlot)
However, I want to give the plots the title of the name of that particular item in the list. I did not manage to fix it within the first lapply, so this is what I did:
plotsTitle <- lapply(names(plots), function(x) plots[[x]] + ggtitle(x))
Now my plots get the correct title.
However, when I look into the list plotsTitles, I don't see any names in this list. So I added this line:
names(plotsTitle) = names(plots)
However, this is not the neatest thing to do so I wonder if there is another way to get the names of the plots visible in the list plotsTitle.