g_geom_line_label: A geom that draws a point at the intercept of linear model...

Description Usage Arguments Examples

View source: R/g_geom_line_label.R

Description

A geom that draws a point at the intercept of linear model estimate

Usage

1
2
3
4
5
6
7
8
9
g_geom_line_label(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

Arguments

...

all the geom_point arguments

Examples

 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
41
42
43
44
45
46
47
48
49
50
# without the function
library(magrittr)
library(dplyr)
cars %>%
  mutate(speed_cat = ifelse(speed > 8,
                               'Fast', 'Slow')) ->
my_cars

my_cars %>%
  group_by(speed_cat) %>%
  filter(speed == max(speed)) ->
 cars_group_endpoint

library(ggplot2)
ggplot(data = my_cars) +
 aes(x = speed, y = dist) +
 aes(color = speed > 8) +
 geom_line() +
 geom_text(data = cars_group_endpoint,
           aes(label = speed_cat),
           hjust = 0, nudge_x = .2)
layer_data(last_plot(), 2)

# the proto and function
StatLineendlabel$compute_group
StatLineendlabel$required_aes
# the proto and function
StatLineendlabel
g_geom_line_label


# using the function
ggplot(data = my_cars) +
 aes(x = speed, y = dist, label = speed > 9) +
 geom_line() +
 g_geom_line_label(size = 4, color = "black") +
 aes(color = speed > 9) +
 aes(group = speed > 9)
 layer_data(last_plot(), 2)

 ggplot(data = my_cars) +
 aes(x = speed, y = dist,
     label = speed_cat %>% factor()) +
 geom_line() +
 g_geom_line_label(size = 4, color = "black",
                   hjust = 0) +
 aes(group = speed_cat) +
 aes(color = speed_cat)
 theme(legend.position = "none")
 layer_data(last_plot(), 2)

EvaMaeRey/ggextend documentation built on Dec. 17, 2021, 7:24 p.m.