PharmApp - Drug Discovery and Development¶
Copyright 2021 | Nghiên Cứu Thuốc | RD Pharma Plus
Email: nghiencuuthuoc@gmail.com | info@nghiencuuthuoc.com
Web: http://www.nghiencuuthuoc.com
See more: https://twitter.com/nghiencuuthuoc | https://facebook.com/nghiencuuthuoc
Coronavirus¶
library(coronavirus)
# update_dataset()
covid19_df <- refresh_coronavirus_jhu()
head(covid19_df)
── Column specification ──────────────────────────────────────────────────────── cols( date = col_date(format = ""), province = col_character(), country = col_character(), lat = col_double(), long = col_double(), type = col_character(), cases = col_double() ) ── Column specification ──────────────────────────────────────────────────────── cols( location = col_character(), location_code = col_character(), location_code_type = col_character() )
date | location | location_type | location_code | location_code_type | data_type | value | lat | long | |
---|---|---|---|---|---|---|---|---|---|
<date> | <chr> | <chr> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | |
1 | 2021-07-12 | Afghanistan | country | AF | iso_3166_2 | recovered_new | 1509 | 33.93911 | 67.70995 |
2 | 2020-02-09 | Afghanistan | country | AF | iso_3166_2 | deaths_new | 0 | 33.93911 | 67.70995 |
3 | 2020-09-18 | Afghanistan | country | AF | iso_3166_2 | cases_new | 25 | 33.93911 | 67.70995 |
4 | 2020-08-22 | Afghanistan | country | AF | iso_3166_2 | cases_new | 59 | 33.93911 | 67.70995 |
5 | 2020-10-12 | Afghanistan | country | AF | iso_3166_2 | cases_new | 71 | 33.93911 | 67.70995 |
6 | 2020-11-20 | Afghanistan | country | AF | iso_3166_2 | recovered_new | 20 | 33.93911 | 67.70995 |
library(dplyr)
summary_df <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
summarise(total_cases = sum(cases)) %>%
arrange(-total_cases)
summary_df %>% head(20)
Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union
country | total_cases |
---|---|
<chr> | <dbl> |
US | 33217995 |
India | 27555457 |
Brazil | 16342162 |
France | 5697076 |
Turkey | 5220549 |
Russia | 4977332 |
United Kingdom | 4489552 |
Italy | 4205970 |
Germany | 3673990 |
Argentina | 3663215 |
Spain | 3663176 |
Colombia | 3319193 |
Iran | 2875858 |
Poland | 2869652 |
Mexico | 2405772 |
Ukraine | 2251242 |
Peru | 1942054 |
Indonesia | 1797499 |
Netherlands | 1664708 |
Czechia | 1659980 |
library(tidyr)
coronavirus %>%
filter(date == max(date)) %>%
select(country, type, cases) %>%
group_by(country, type) %>%
summarise(total_cases = sum(cases)) %>%
pivot_wider(names_from = type,
values_from = total_cases) %>%
arrange(-confirmed)
`summarise()` has grouped output by 'country'. You can override using the `.groups` argument.
country | confirmed | death | recovered |
---|---|---|---|
<chr> | <dbl> | <dbl> | <dbl> |
India | 186364 | 3660 | 259459 |
Brazil | 67467 | 2245 | 183636 |
Argentina | 41080 | 547 | 38186 |
US | 27525 | 1338 | 0 |
Colombia | 25092 | 513 | 22425 |
France | 13933 | 142 | 977 |
Iran | 9994 | 165 | 17401 |
Russia | 8911 | 395 | 9593 |
Turkey | 8426 | 183 | 13102 |
Chile | 8105 | 185 | 5542 |
Malaysia | 7857 | 59 | 4598 |
South Africa | 7707 | 101 | 2632 |
Germany | 6949 | 192 | 10840 |
Nepal | 6731 | 106 | 7226 |
Philippines | 6454 | 210 | 4172 |
Indonesia | 6278 | 136 | 3924 |
Thailand | 5386 | 47 | 0 |
Spain | 5290 | 33 | 0 |
Peru | 4809 | 182 | 5661 |
Canada | 4721 | 90 | 8557 |
Iraq | 4611 | 22 | 4059 |
Japan | 4163 | 118 | 5111 |
Italy | 4143 | 171 | 10808 |
Uruguay | 3937 | 44 | 3017 |
Ukraine | 3637 | 190 | 17033 |
United Kingdom | 3384 | 10 | 3 |
Netherlands | 3344 | 16 | 26 |
Paraguay | 3136 | 99 | 2225 |
Bahrain | 3052 | 20 | 1970 |
Mexico | 3050 | 429 | 1689 |
⋮ | ⋮ | ⋮ | ⋮ |
Congo (Brazzaville) | 0 | 0 | 0 |
Diamond Princess | 0 | 0 | 0 |
Dominica | 0 | 0 | 0 |
El Salvador | 0 | 4 | 0 |
Equatorial Guinea | 0 | 0 | 0 |
Gabon | 0 | 0 | 0 |
Grenada | 0 | 0 | 0 |
Haiti | 0 | 0 | 0 |
Holy See | 0 | 0 | 0 |
Iceland | 0 | 0 | 0 |
Ireland | 0 | 0 | 0 |
Kiribati | 0 | 0 | 0 |
Liberia | 0 | 0 | 0 |
Malawi | 0 | 0 | 0 |
Marshall Islands | 0 | 0 | 0 |
Micronesia | 0 | 0 | 0 |
Monaco | 0 | 0 | 1 |
MS Zaandam | 0 | 0 | 0 |
New Zealand | 0 | 0 | 0 |
Nicaragua | 0 | 0 | 0 |
Saint Vincent and the Grenadines | 0 | 0 | 0 |
Samoa | 0 | 0 | 0 |
San Marino | 0 | 0 | 0 |
Sao Tome and Principe | 0 | 0 | 0 |
Solomon Islands | 0 | 0 | 0 |
Sudan | 0 | 0 | 0 |
Tajikistan | 0 | 0 | 0 |
Tanzania | 0 | 0 | 0 |
Vanuatu | 0 | 0 | 0 |
West Bank and Gaza | 0 | 0 | 0 |
library(plotly)
coronavirus %>%
group_by(type, date) %>%
summarise(total_cases = sum(cases)) %>%
pivot_wider(names_from = type, values_from = total_cases) %>%
arrange(date) %>%
mutate(active = confirmed - death - recovered) %>%
mutate(active_total = cumsum(active),
recovered_total = cumsum(recovered),
death_total = cumsum(death)) %>%
plot_ly(x = ~ date,
y = ~ active_total,
name = 'Active',
fillcolor = '#1f77b4',
type = 'scatter',
mode = 'none',
stackgroup = 'one') %>%
add_trace(y = ~ death_total,
name = "Death",
fillcolor = '#E41317') %>%
add_trace(y = ~recovered_total,
name = 'Recovered',
fillcolor = 'forestgreen') %>%
layout(title = "Distribution of Covid19 Cases Worldwide",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of Cases"),
xaxis = list(title = "Source: Johns Hopkins University Center for Systems Science and Engineering"))
Loading required package: ggplot2 Attaching package: ‘plotly’ The following object is masked from ‘package:ggplot2’: last_plot The following object is masked from ‘package:stats’: filter The following object is masked from ‘package:graphics’: layout `summarise()` has grouped output by 'type'. You can override using the `.groups` argument.
conf_df <- coronavirus %>%
filter(type == "confirmed") %>%
group_by(country) %>%
summarise(total_cases = sum(cases)) %>%
arrange(-total_cases) %>%
mutate(parents = "Confirmed") %>%
ungroup()
plot_ly(data = conf_df,
type= "treemap",
values = ~total_cases,
labels= ~ country,
parents= ~parents,
domain = list(column=0),
name = "Confirmed",
textinfo="label+value+percent parent")
Không có nhận xét nào :
Đăng nhận xét