Reputation: 11
I have to create a plot with the number of COVID-19 confirmed cases by date, in each country. I have to use the data inside the package: https://cran.r-project.org/web/packages/coronavirus/index.html.
I managed to create a subset with the variables "Country Region", "Type" (confirmed only), "date", and "total of cases". However, i don't know to plot a graph with multiple lines.
I have to plot a graph with all countries in it, based on the: https://twitter.com/thomasfujiwara/status/1249817958874001412?s=20
I also want to exclude mainland china from the dataset
Can someone help me?
Upvotes: 0
Views: 455
Reputation: 1868
It's very difficult to help without a reproducible example, but one way would be to use ggplot2
. You can use either the group
or the color
aesthetic in your plot:
library(coronavirus)
library(dplyr)
library(ggplot2)
data(coronavirus)
coronavirus %>%
filter(type == "confirmed") %>%
filter(Country.Region != "Mainland China") %>%
group_by(Country.Region, date) %>%
summarise(total = sum(cases)) %>%
ggplot(aes(x = date, y = total, color = Country.Region)) +
geom_line()
Upvotes: 2