Created
February 16, 2022 13:10
-
-
Save richarddmorey/b54abbf097cfdf9aee61a22c75b34b6b to your computer and use it in GitHub Desktop.
Adding points to ends of lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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