0

I'm trying to plot graphs with a Covid-2019 dataset. I was already able to plot one with the number of confirmed cases by countries, but now I need one with the number of casualties per country. How can I do that? This was the code I used for the number of confirmed cases:

library(ggplot2)

library('remotes')
remotes::install_github("GuangchuangYu/nCov2019", dependencies = TRUE)

library('nCov2019')
get_nCov2019(lang = 'en')

x <- get_nCov2019()
y <- load_nCov2019()

library(magrittr)

d <- y['global'] 
f <- d %>% dplyr::filter(time == time(y)) %>% top_n(180, cum_confirm) %>% arrange(desc(cum_confirm)) 

library(dplyr)

require(ggplot2)
require(ggrepel)
ggplot(filter(d, d$time > '2020-02-05' & country %in% f$country), mapping = aes(time, cum_confirm , color = country, label = country))  +
geom_line() +
  geom_text(data = f, aes(label = country, colour = country, x = time, y = cum_confirm))+
theme_minimal(base_size = 14)+
theme(legend.position = "none") +
ggtitle('Covid-19 Cases by Country', 'The progression of confirmed cases by countries')+
ylab('Confirmed Cases')
  • 1
    Hi tcaraujo, welcome to Stack Overflow. It will be much easier to help if you provide the code you've been using thus far. Additionally, can you clarify what you mean by "automatically updated"? See [How to make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more info. – Ian Campbell Apr 23 '20 at 17:25
  • Hi Ian, I just edited the question to include the code I used for the confirmed cases per country. However, I can't seem to plot the same type of graph for the number of casualties. – tcaraujo21 Apr 23 '20 at 17:53

1 Answers1

1

I worry that my solution is too simple, but your object f appears to also contain the number of casualities in the cum_dead column.

I think all you need to do is change cum_confirm to cum_dead.

ggplot(filter(d, d$time > '2020-02-05' & country %in% f$country), mapping = aes(time, cum_confirm , color = country, label = country))  +
geom_line() +
  geom_text(data = f, aes(label = country, colour = country, x = time, y = cum_dead))+
theme_minimal(base_size = 14)+
theme(legend.position = "none") +
ggtitle('Covid-19 Cases by Country', 'The progression of confirmed cases by countries')+
ylab('Confirmed Dead')

enter image description here

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57