Area Line Plot with Multiple Series
We can create area line plots with multiple series, each represented by a separate line and filled area. Here’s an example with two series.
R
# Create data with multiple series set.seed (789) df_multiple_series <- data.frame ( Year = 2000:2020, Series1 = cumsum ( rnorm (21)), Series2 = cumsum ( rnorm (21)) ) # Create an area line plot with multiple series ggplot (df_multiple_series, aes (x = Year)) + geom_area ( aes (y = Series1, fill = "Series 1" ), alpha = 0.5) + geom_area ( aes (y = Series2, fill = "Series 2" ), alpha = 0.5) + labs ( title = "Area Line Plot with Multiple Series" , x = "Year" , y = "Cumulative Value" ) + scale_fill_manual (values = c ( "Series 1" = "blue" , "Series 2" = "red" )) + theme_minimal () |
Output:
In this example, we create an area line plot with two series (Series 1 and Series 2). Each series is represented by a separate line and filled area. We use the alpha argument to control the transparency of the filled areas. The scale_fill_manual function is used to specify custom fill colors for the two series.
Area Line Plot in R
Area line plots, commonly referred to as filled area plots, are effective data visualisation techniques in R for showing how data evolves over time. They are particularly helpful for displaying trends, distributions, and time series data. In this article, we’ll look at how to use the well-liked ggplot2 programme to generate area line plots in R.