如何为时间序列中的最后日期添加点或标记

How to add a point or marker for the last date in a time series

在下面的代码中,我试图将每个变量的最后一个数据点转换为一个点或不同的标记。我应该做些什么修改才能达到这个目的?

library(ggplot2)
ggplot(economics_long, aes(date, value))+ geom_line() + facet_wrap(~variable, scales = "free_y", ncol = 1)

只需添加一个 geom_point 图层,在其中使用针对最后日期过滤的数据集,例如

library(ggplot2)
library(dplyr)

ggplot(economics_long, aes(date, value)) + 
  geom_line() +
  geom_point(data = group_by(economics_long, variable) %>% filter(date == last(date))) +
  facet_wrap(~variable, scales = "free_y", ncol = 1)