Skip to content
This repository
Newer
Older
100644 75 lines (65 sloc) 2.455 kb
953fe471 »
2010-12-31 Convert all documentation to roxygen
1 #' Add a smoothed conditional mean.
2 #'
1244716e »
2014-02-24 Trim whitespace
3 #' @section Aesthetics:
d7971cbf »
2012-05-23 Fix document aesthetics.
4 #' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "smooth")}
5 #'
7b5d0a73 »
2011-12-21 Inherit geom parameters
6 #' @inheritParams geom_point
1244716e »
2014-02-24 Trim whitespace
7 #' @seealso The default stat for this geom is \code{\link{stat_smooth}} see
119b1029 » unknown
2012-01-03 Add aes pages and translate pages
8 #' that documentation for more options to control the underlying statistical transformation.
953fe471 »
2010-12-31 Convert all documentation to roxygen
9 #' @export
10 #' @examples
11 #' # See stat_smooth for examples of using built in model fitting
12 #' # if you need some more flexible, this example shows you how to
13 #' # plot the fits from any model of your choosing
14 #' qplot(wt, mpg, data=mtcars, colour=factor(cyl))
1244716e »
2014-02-24 Trim whitespace
15 #'
953fe471 »
2010-12-31 Convert all documentation to roxygen
16 #' model <- lm(mpg ~ wt + factor(cyl), data=mtcars)
17 #' grid <- with(mtcars, expand.grid(
18 #' wt = seq(min(wt), max(wt), length = 20),
19 #' cyl = levels(factor(cyl))
20 #' ))
1244716e »
2014-02-24 Trim whitespace
21 #'
953fe471 »
2010-12-31 Convert all documentation to roxygen
22 #' grid$mpg <- stats::predict(model, newdata=grid)
1244716e »
2014-02-24 Trim whitespace
23 #'
953fe471 »
2010-12-31 Convert all documentation to roxygen
24 #' qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + geom_line(data=grid)
1244716e »
2014-02-24 Trim whitespace
25 #'
953fe471 »
2010-12-31 Convert all documentation to roxygen
26 #' # or with standard errors
1244716e »
2014-02-24 Trim whitespace
27 #'
953fe471 »
2010-12-31 Convert all documentation to roxygen
28 #' err <- stats::predict(model, newdata=grid, se = TRUE)
29 #' grid$ucl <- err$fit + 1.96 * err$se.fit
30 #' grid$lcl <- err$fit - 1.96 * err$se.fit
1244716e »
2014-02-24 Trim whitespace
31 #'
32 #' qplot(wt, mpg, data=mtcars, colour=factor(cyl)) +
33 #' geom_smooth(aes(ymin = lcl, ymax = ucl), data=grid, stat="identity")
34 geom_smooth <- function (mapping = NULL, data = NULL, stat = "smooth", position = "identity", ...) {
ede677cb » JakeRuss
2011-06-28 Removed xxx.r (build_accessor file) and @name tags, added functions t…
35 GeomSmooth$new(mapping = mapping, data = data, stat = stat, position = position, ...)
36 }
37
e3ccb4ed »
2008-07-06 Fix a few GeomInterval->Geom that I missed
38 GeomSmooth <- proto(Geom, {
46c1796d »
2011-01-04 Fix loading problems
39 objname <- "smooth"
40
61984574 »
2007-11-06 Add ggplot
41 draw <- function(., data, scales, coordinates, ...) {
36d5ad2e »
2009-02-28 New aesthetic alpha.
42 ribbon <- transform(data, colour = NA)
84400ad8 »
2012-04-20 Preserve alpha by default.
43 path <- transform(data, alpha = NA)
1244716e »
2014-02-24 Trim whitespace
44
a59c07f0 »
2010-06-30 Minor fixes to code and examples to get all examples
45 has_ribbon <- function(x) !is.null(data$ymax) && !is.null(data$ymin)
1244716e »
2014-02-24 Trim whitespace
46
61984574 »
2007-11-06 Add ggplot
47 gList(
a59c07f0 »
2010-06-30 Minor fixes to code and examples to get all examples
48 if (has_ribbon(data)) GeomRibbon$draw(ribbon, scales, coordinates),
f44b4e9e »
2009-05-15 Fix ordering bug
49 GeomLine$draw(path, scales, coordinates)
61984574 »
2007-11-06 Add ggplot
50 )
51 }
52
483779b8 »
2008-02-20 Ensure all geoms have correct legend type. Add set_scale_default func…
53 guide_geom <- function(.) "smooth"
1244716e »
2014-02-24 Trim whitespace
54
61984574 »
2007-11-06 Add ggplot
55 default_stat <- function(.) StatSmooth
56 required_aes <- c("x", "y")
9af2ccff »
2008-09-04 Make aesthetics more consistent
57 default_aes <- function(.) aes(colour="#3366FF", fill="grey60", size=0.5, linetype=1, weight=1, alpha=0.4)
61984574 »
2007-11-06 Add ggplot
58
483779b8 »
2008-02-20 Ensure all geoms have correct legend type. Add set_scale_default func…
59
826e499e »
2008-12-09 Legend improvements
60 draw_legend <- function(., data, params, ...) {
483779b8 »
2008-02-20 Ensure all geoms have correct legend type. Add set_scale_default func…
61 data <- aesdefaults(data, .$default_aes(), list(...))
0ff9255e »
2008-06-10 Minor doc tweaks
62 data$fill <- alpha(data$fill, data$alpha)
e23c5311 »
2009-05-18 Fix bug in geom_smooth legend
63 data$alpha <- 1
1244716e »
2014-02-24 Trim whitespace
64
826e499e »
2008-12-09 Legend improvements
65 if (is.null(params$se) || params$se) {
66 gTree(children = gList(
67 rectGrob(gp = gpar(col = NA, fill = data$fill)),
68 GeomPath$draw_legend(data, ...)
1244716e »
2014-02-24 Trim whitespace
69 ))
826e499e »
2008-12-09 Legend improvements
70 } else {
483779b8 »
2008-02-20 Ensure all geoms have correct legend type. Add set_scale_default func…
71 GeomPath$draw_legend(data, ...)
826e499e »
2008-12-09 Legend improvements
72 }
483779b8 »
2008-02-20 Ensure all geoms have correct legend type. Add set_scale_default func…
73 }
61984574 »
2007-11-06 Add ggplot
74
75 })
Something went wrong with that request. Please try again.