本文参考自 Line chart with small multiple 一文,代码略有修改,供参考。
加载相关 R 包 use("dplyr", c("mutate", "select", "slice_max")) library(ggplot2) library(ggtext) library(patchwork) # 准备数据 # url = "https://raw.githubusercontent.com/holtzy/R-graph-gallery/master/DATA/dataConsumerConfidence.csv" # ipkg::download_file(url, "dataConsumerConfidence.csv") # 对数据进行预处理 file_path = "./dataConsumerConfidence.csv" file_path |> read.csv() |> mutate(date = lubridate::my(Time)) |> select(-Time) |> tidyr::pivot_longer( …