Skip to content

Instantly share code, notes, and snippets.

@richarddmorey
Created February 16, 2022 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddmorey/b54abbf097cfdf9aee61a22c75b34b6b to your computer and use it in GitHub Desktop.
Save richarddmorey/b54abbf097cfdf9aee61a22c75b34b6b to your computer and use it in GitHub Desktop.
Adding points to ends of lines
library(dplyr)
library(ggplot2)
# Create data
tibble(
g = rep(c('A','B'), each = 50),
z = rnorm(length(g))
) |>
group_by(g) |>
mutate(
y = cumsum(z),
x = row_number() + g %in% 'B' # offset a bit
) %>%
ungroup() -> tbl
tbl |>
ggplot(aes(x=x,y=y,group=g,color=g)) +
geom_line() +
geom_point(
data = tbl %>%
group_by(g) %>%
filter(x %in% range(x))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment