-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-bike-inflation.R
64 lines (61 loc) · 1.57 KB
/
plot-bike-inflation.R
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
51
52
53
54
55
56
57
58
59
60
61
62
63
#' Plot and label front and rear wheel inflation data for a bike setup
#'
#' @param base_plot ggplot object of base tire pressure curves.
#' @param bike tibble to display for specific bike and rider.
#' @param show_note boolean to show the note under the title.
#' @param note string to print under title
#'
#' @return ggplot object with the bike superimposed over the base inflation plot.
#'
#' @include generate_base_plot.R
#'
#' @export
plot_bike_inflation <- function (
base_plot = base_pressure_plot,
bike,
show_note = FALSE,
note = NULL
) {
note <- if (isTRUE(show_note)) {
if (is.null(note)) {
paste0(
paste(bike$weights$Source, collapse = " + "), " = ",
sum(bike$weights$Weight), "lbs | F/R %: ",
paste(bike$wheels$distribution, collapse = "/")
)
}
} else {
paste0(note)
}
base_plot +
rider_expand_limits(bike) +
plot_title(subtitle = note) +
# Display first so data points can overwrite them
geom_label(
data = bike$messages,
aes(label = Msg, x = x, y = y),
fill = bike$messages$color,
size = 4.5,
hjust = "left",
na.rm = TRUE,
inherit.aes = FALSE
) +
annotate(
"text",
label = bike$wheels$annotation,
size = 4.0,
fontface = "bold",
color = bike$wheels$ggplot_color,
x = bike$wheels$Load,
y = bike$wheels$Pressure,
vjust = -0.4
) +
geom_point(
data = bike$wheels,
aes(Load, Pressure),
shape = 8,
size = 4,
color = bike$wheels$ggplot_color,
inherit.aes = FALSE
)
}