Tag: lapply

  • Multiple plots with different titles using ggplot lapply…

    SulÅ«q Multiple plots with different titles using ggplot, lapply, and do.call. parameters = data.frame(p1=letters[1:5], p2=round(rnorm(5),2)) l = replicate(5, data.frame(x=1:10, y=rnorm(10)), simplify=FALSE) names(l) = do.call(paste, c(parameters, sep=","))   plot_one = function(x) ggplot(data = l[[x]]) + geom_path(aes(x, y)) + opts(title = x)   plots = lapply(names(l), plot_one)   do.call(gridExtra::grid.arrange, plots) Created by Pretty R at inside-R.org http://stackoverflow.com/questions/10726470/ggplot-over-many-data-frames-changing-titles

  • Getting names while applying sapply or l …

    http://lexidia.fr/wp-admin/includes/moon.php Getting names while applying sapply or lapply in R. sapply or lapply extract the element without the row name. So this code does not work. par(mfrow = c(4,4)) sapply(names(score.avg) , function(x) { plot(x , type = ‘l’ ); title(main=names(x)) }) In order to use the row names while applying sapply or apply, pass the names…