This is a test version of Biostars. For the public version, visit https://www.biostars.org.
What is this visual/graph called? I am trying to achieve this using R.

This site shows the rise of coViD variants over a period of time

The smoothened plot of frequency of the variants over a period of time.

What is the best way to achieve this in R. I tried area plot using ggplot2. I have sharp peaks and unable to smoothen them out. Attached is the image I got using area plot in ggplot2.The plot I got using ggplot2 (area plot)

r visuals graph

some plotting data Example data

g <- ggplot(subset(avg_df, State %in% c("State_name")), aes(x = Date, y = mean))+ geom_area(aes(fill = variable)) + guides(fill = guide_legend(title = "SC-2 variants")) + scale_fill_manual(values=met.brewer("Demuth")) + facet_grid(~State, scales='free_x') + theme(panel.spacing = unit(.5, "lines"), panel.border = element_rect(color = "black", fill = NA, size = 2), strip.background = element_rect(color = "black", size = 1.5))

1 answer

Its a stacked plot you can make it in ggplot via https://ggplot2.tidyverse.org/reference/position_stack.html

you can also try geom_density

library(ggplot2)

 ggplot(data=diamonds, aes(x=price, group=cut, fill=cut)) +
  geom_density(adjust=1.5, position="fill") +
  theme_bw()

Created on 2022-08-21 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)

Thank you. g <- ggplot(avg_df, aes(x = mean, fill=variable))+ geom_density(position = "fill") + guides(fill = guide_legend(title = "SC-2 variants")) + scale_fill_manual(values=colors) + facet_grid(~State, scales='free_x')

I am unable to plot it with Date as the x axis. I need the date as the x axis with the abundance as the y axis.

If you want to plot with the data as the X-axis, you need to supply it as the x = value within the aes() call: aes(x = Date, y = mean, fill = variable). Or am I misunderstanding your problem here?

I apologize. I wasn't clear. I want the dates plotted against the abundance. But in geom density, since it will plot against only the density its not plotting when I have x = Date and y mean. ggplot(data=avg_df, aes(x=Date, fill=variable)) + geom_density(adjust=1.5, position="fill") + theme_bw()

The above works. I get something like this graph. This is with all the data points. The y axis is density

When I do this code... ggplot(data=avg_df, aes(x=Date, y=mean, fill=variable)) + geom_density(adjust=1.5, position="fill") + theme_bw()

its not plotting properly

Log in to answer this question.