【发布时间】:2021-08-26 08:48:08
【问题描述】:
我尝试为每个日期画线 COVID 病例。我没有输出,讲师只是提出问题。我解决了这个问题,但我的问题是输出。看起来很奇怪。这是问题: “对于总死亡人数最高的十个国家,绘制以下折线图,以可视化流行病是否已经开始放缓,以及这些国家的新病例/死亡人数增长率有何不同。 a) 每个日期的新病例数(绝对数与每 100.000 人)"
这是我的代码:
library(utils)
COVID_data <-read.csv("https://opendata.ecdc.europa.eu/covid19/nationalcasedeath_eueea_daily_ei/csv", na.strings = "", fileEncoding = "UTF-8-BOM")
#Finding ten countries where the highest absolute total deaths number is
abs_total_deaths <-COVID_data %>%
group_by(countriesAndTerritories) %>%
summarise(abs_total_deaths = sum(deaths)) %>%
arrange(desc(abs_total_deaths))
abs_ten_total_deaths <- c('Italy','France','Germany','Spain','Poland',
'Romania','Czechia','Hungary','Belgium','Bulgaria')
#Calculate new cases by dividing absolute number to 100.000 population
#Draw line for each country
COVID_data %>%
filter(countriesAndTerritories %in% abs_ten_total_deaths) %>%
filter(cases >0) %>%
mutate(new_cases = cases/100000) %>%
ungroup() %>%
ggplot()+
geom_line(aes(x = dateRep, y = new_cases, color = countriesAndTerritories),size=1)+
labs(x="Date",
y="New Cases",
title="New Cases per 100.000 population") +
facet_wrap(~countriesAndTerritories)+
theme_bw()
我还将添加我的输出图片。我认为我的图表不正确,因为输出看起来很奇怪。我不明白我在哪里犯了错误。如果你帮助我,我将不胜感激。 这是输出:
【问题讨论】:
-
mutate(new_cases = cases/100000)不会为您提供每 100000 人的比率。像mutate(new_cases = cases * 100000 /<population>)这样的东西会更好,其中<population>是您的人口变量。 -
@Limey 非常感谢。我修复了它,但图表看起来还是一样的。我该如何解释...您能在 x 轴上查看 March 吗?线掉下来了,正常吗?