r_eda

ggplot 折线末端加入标签

参考 drsimonj

suppressMessages(library(tidyverse))
Orange %>% 
    group_by(Tree) %>% 
    top_n(1, age) %>% 
    pull(circumference) ->
end_label
args(top_n)
## function (x, n, wt) 
## NULL

wt
(Optional). The variable to use for ordering.

Orange %>% 
    ggplot(aes(x = age, y = circumference, col = Tree)) +
    geom_line() +
    scale_y_continuous(sec.axis = sec_axis(~ ., breaks = end_label))

sec.axis 第二个坐标轴。