How to give arrows only to certain lines

45 Views Asked by At

Say that I have lines as follows (with code taken directly from coloring specific data in an arrow plot in R):

data <- tibble(ID = c(rep(1, 3), rep(2,3)), year = rep(2018:2020, 2), x = c(1.2, 1.6, -1.1, 3.2, 3.8, 1.9), y = c(3, -2, 6, -1, 2, 3)) %>% 
    group_by(ID) %>% 
    mutate(label = ifelse(row_number() == 1, ID, "")) %>% 
    ungroup()

data %>% 
    ggplot(aes(x = x, y = y, label = label, group = ID)) + 
    geom_path(arrow = arrow()) + 
    geom_path(data = data %>% filter(year == 2020),arrow = arrow(),mapping = aes(color = as.factor(year), group = 1)) + 
    geom_text(nudge_x = .2, nudge_y = 0)

If I wanted to only have line 1 have an error, how would I do this? Would I have to graph the lines separately from the arrows (and filter as is done in the code below)?

0

There are 0 best solutions below