annotations/
annotations.rs1use ggplot_rs::prelude::*;
2use polars::prelude::*;
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let month: Vec<f64> = (1..=12).map(|i| i as f64).collect();
7 let sales = vec![
8 120.0, 135.0, 150.0, 180.0, 210.0, 310.0, 280.0, 250.0, 190.0, 170.0, 155.0, 140.0,
9 ];
10
11 let df = df! {
12 "month" => month,
13 "sales" => sales,
14 }?;
15
16 GGPlot::new(df)
17 .aes(Aes::new().x("month").y("sales"))
18 .geom_line()
19 .geom_point()
20 .annotate_rect(4.5, 7.5, 100.0, 320.0)
22 .annotate_text("Summer Peak", 6.0, 330.0)
24 .annotate_segment(7.5, 330.0, 6.2, 312.0)
26 .title("Monthly Sales with Annotations")
27 .xlab("Month")
28 .ylab("Sales ($)")
29 .save("annotations.svg")?;
30
31 println!("Saved annotations.svg");
32 Ok(())
33}