I want to create a stacked area chart using geom_area() for a dataset which has dates a x-axis and frequency as y-axis. My dataset looks like this
Date Variant. Frequency
2020-08-01 AY.1 0
2020-08-01 B.1.351 0
2020-08-01 B.1.617.1 0
2020-08-01 B.1.617.2 0
2020-08-01 B.1.617.3 0
2020-08-01 others 1
2020-08-01 others 1
2020-09-01. AY.1 0
2020-09-01 B.1.351 0
2020-09-01 B.1.617.1 0
2020-09-01 B.1.617.2 0
2020-09-01 B.1.617.3 0
2020-09-01 others 1
2020-09-01 others 1
.
.
.
.
2021-08-03 B.1.617.3 0.00564
2021-08-03 others 0.36
2021-08-03 others 0.36
2021-08-04 AY.1 0.000713
2021-08-04 AY.4 0.42
2021-08-04 B.1.1.7 0.00546
2021-08-04 B.1.351 0.00137
2021-08-04 B.1.617.1 0.0109
2021-08-04 B.1.617.2 0.22
I have tried using the following code to create a stacked area plot -
data %>%
ggplot(aes(x=Date, y=Frequency, fill=Variant)) +
geom_area(position = 'fill', alpha=0.8) +
scale_x_date(date_breaks = '1 month', date_labels = '%b-%y',expand = c(0.01,0))
However, I end up with an unexpected output which looks like this

I tried changing the position setting to 'identity' with geom_area(position='identity'), it gives an improved output, but not what I desire.

I would like the output to look something like a basic stacked area chart in R -

I have tried geom_bar() as well which gives me a stacked barplot but I would like to create the similar chart with area
To create a Stacked area chart:
Most important is the shape of your data. As r2evans already mentioned.
Here I took your fragmented dataframe and modified it with additional columns to show how your data should be organized to plot this kind of plot.
Basically you need a repeating group over time with certain values -> here group a:g, time 1:6, and Frequency:
modified fake data
code for plot:
resulting plot:
fake data: