File: smooth.r

package info (click to toggle)
r-cran-ggvis 0.4.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,716 kB
  • sloc: sh: 25; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
library(ggvis)

# Scatter plot with loess model line
mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  layer_points() %>%
  compute_smooth(mpg ~ wt, se = F) %>%
  layer_paths(x = ~pred_, y = ~resp_, stroke := "red")

# Or with shorthand layer_smooth
mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  layer_points() %>%
  layer_smooths(stroke := "red")

# With confidence region
mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  layer_points() %>%
  layer_smooths(stroke := "red", se = TRUE)

# Scatter plot with lm model line
mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  layer_points() %>%
  layer_model_predictions(stroke := "red", model = "lm")

# Scatterplot with lm and loess
mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  layer_points() %>%
  layer_smooths(stroke := "blue") %>%
  layer_model_predictions(stroke := "red", model = "lm")

# Scatter plot with smooth for each level of cyl
mtcars %>% ggvis(x = ~wt, y = ~mpg, stroke = ~factor(cyl)) %>%
  group_by(cyl) %>%
  layer_points() %>%
  layer_smooths()

# Scatter plot with smooth for each level of cyl, but only points coloured
mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  group_by(cyl) %>%
  layer_points(fill = ~factor(cyl)) %>%
  layer_smooths()