What is this visual/graph called? I am trying to achieve this using R.
1
0
Entering edit mode
20 months ago
pramach1 ▴ 40

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 • 1.0k views
ADD COMMENT
0
Entering edit mode

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))

ADD REPLY
2
Entering edit mode
20 months ago
LDT ▴ 340

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)

ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1778 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6