Many thanks for your kind help!! Li 2010/2/11 Dieter Menne <dieter.me...@menne-biomed.de>
> > > Dennis Murphy wrote: > > > > > > ## Histogram + density plots in lattice and ggplot2 > > > > > > There was a typo in your example (should be dd <- data.frame), but anyway. > ggplot2 needs 10 times as long. While Bill Venables (?) would argue "what > are you going to do with 3 seconds in your life", it adds up in lengthy > Sweave reports (yes... caching would be an option). > > Still preferring lattice. > > Dieter > > > # example data frame > library(ggplot2) > library(lattice) > > dd <- data.frame(x = rnorm(600), g = factor(rep(1:6, each = 100))) > > # lattice > system.time( > print(histogram(~ x | g, data = dd, type = 'density', > panel = function(x, subscripts, ...) { > panel.histogram(x, ...) > panel.mathdensity(dnorm, col = 'red', ...) > panel.densityplot(x, plot.points = FALSE, col = 'navy',...) > } )) > ) > # 0.33 seconds > > # ggplot2 > system.time( > print( ggplot(data = dd, aes(x = x, group = g)) + > geom_histogram(aes(y = ..density..), binwidth = 0.5) + > geom_density(color = 'navy') + stat_function(fun = 'dnorm') + > facet_wrap(~ g, ncol = 3) + ylab("Density")) > ) > > # 3.7 seconds > > -- > View this message in context: > http://n4.nabble.com/histogam-plots-tp1476859p1477632.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.