Ajustando os dados

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

wb_cs <- read_csv(
  "https://joachim-gassen.github.io/data/jh_add_wbank_data.csv", 
  col_types = cols()
)
dta<-data2

colnames(dta)[5]<-c("country")
colnames(dta)[9]<-c("continente")
colnames(dta)[1]<-"date"
colnames(dta)[3]<-"confirmed"
colnames(dta)[4]<-"deaths"
dta[,1]<-dmy(dta[,1])
colnames(dta)[7]<-"iso3c"
colnames(dta)[7]<-"iso3c"
colnames(wb_cs)
## [1] "iso3c"            "population"       "land_area_skm"    "pop_density"     
## [5] "pop_largest_city" "gdp_capita"       "life_expectancy"  "region"          
## [9] "income"
data$date<-ymd(data$date)

dta2<- left_join(dta,wb_cs,by="iso3c")
dta2$country<-gsub("_"," ",dta2$country)
data$location<-gsub("United States", "United States of America",data$location)
dta3<- left_join(dta2,data,by=c("country"="location","date"))

dta3 %>% group_by(country) %>% arrange(date) %>% mutate(mortes=cumsum(deaths))->dta4

dta4 %>% group_by(country) %>% filter(total_vaccinations!="NA" | country=="Brazil" | country=="United States of America") %>% summarise(tail(total_vaccinations,1),max(mortes))->tabela1
## `summarise()` ungrouping output (override with `.groups` argument)
#library(xlsx)
#write.xlsx(tabela1, "vacina2.xlsx")

dados4<-dta4 %>%
        filter(country %in% c("Brazil", "United States of America", "United Kingdom"))

dados4$total_vaccinations[is.na(dados4$total_vaccinations)]<-0
dados4$daily_vaccinations[is.na(dados4$daily_vaccinations)]<-0
dados4$people_vaccinated[is.na(dados4$people_vaccinated)]<-0


library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
ks <- function (x) { number_format(accuracy = 1,
                                   scale = 1/1000,
                                   suffix = "k",
                                   big.mark = ",")(x) }
dados4 %>% 
    ggplot(aes(x = date, 
                      y = confirmed)) +
    geom_col(alpha = 2/10, linetype = 0) + 
    geom_line(data = dados4, 
                       mapping = aes(x = date, 
                                     y = total_vaccinations, 
                                     color = "darkred",
                                     ), show.legend = FALSE) +  
     facet_grid(rows = vars(country), scales = "free_y")  +
    labs(title = "Covid e Vacinação", 
                  subtitle = paste0("Infectados desde o Inicio"),
                  y = "Infectados",
                  x = "Dias") + theme_wsj()+
  theme(axis.title.x = element_blank(),
        axis.text = element_text(size = 8)) + scale_y_continuous(labels=ks)

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.