'How to add titles to each plot created from lapply in R?
I am trying to add the variable name (i.e., x, y, and z) as the title for each boxplot:
bpdf = data.frame(group=c("A","A","A","B","B","B","C","C","C"),
x=c(1,1,2,2,3,3,3,4,4),
y=c(7,5,2,9,7,6,3,1,2),
z=c(4,5,2,9,8,9,7,6,7))
par(mfrow=c(1,3))
lapply(bpdf[-1],function(x){
y <- sort(tapply(x,bpdf$group,median),decreasing=TRUE)
boxplot(x~factor(bpdf$group,levels=names(y)),
main=paste(colnames(bpdf[-1])))
})
I am missing something in the main call (ht to agstudy for previous help).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
