Как я могу построить линейный график, используя тот же набор данных? - PullRequest
0 голосов
/ 23 апреля 2020

Я пытаюсь построить графики с набором данных Covid-2019. Мне уже удалось составить один график с количеством подтвержденных случаев по странам, но теперь мне нужен один с числом жертв на страну. Как я могу это сделать? Это был код, который я использовал для числа подтвержденных случаев:

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 Ответ

1 голос
/ 23 апреля 2020

Я беспокоюсь, что мое решение слишком простое, но ваш объект f также содержит количество несчастных случаев в столбце cum_dead.

Я думаю, все, что вам нужно сделать, это изменить cum_confirm на 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

...