Implement an R function to generate a linr graph depicting the trend of a time-series dataset , with separate lines for each group ,utilizing ggplot2’s group aesthetic
Step 1: Load necessary libraries
library(ggplot2)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
plot_time_series <-function(data, x_col,y_col,group_col,title="AirPassenger Trends") {ggplot(data, aes_string(x = x_col, y = y_col, color = group_col, group = group_col))+geom_line(size =1.2)+geom_point(size =2) +labs(title = title,x ="Year",y ="Number of Passangers",color ="Year") +theme_minimal() +theme(legend.position ="top")}plot_time_series(data, "Date","Passengers","Year","Treand of Airline Passenger over Time")
Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
ℹ Please use tidy evaluation idioms with `aes()`.
ℹ See also `vignette("ggplot2-in-packages")` for more information.
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.