---
title: "Casos de coronavirus a Espanya"
author: "Francesc Carmona"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Les dades

```{r}
jhu_url <- paste("https://raw.githubusercontent.com/CSSEGISandData/", 
                 "COVID-19/master/csse_covid_19_data/", "csse_covid_19_time_series/", 
                 "time_series_19-covid-Confirmed.csv", sep = "")
confirmed_long_jhu <- read.csv(jhu_url) 
```

Ara mirem el contingut i llegim les dades d'Espanya:
```{r}
class(confirmed_long_jhu)
dim(confirmed_long_jhu)
str(confirmed_long_jhu[,1:6]) # mirem les primeres 6 variables
head(confirmed_long_jhu[,1:2]) # mirem la capçalera de les 2 primeres variables
tail(confirmed_long_jhu[,1:2]) # mirem el final de les 2 primeres variables
spain <- which(confirmed_long_jhu[,2] == "Spain") 
confirmed_long_jhu[spain,1:5]
```

## El gràfic

Per fer el gràfic hem de millorar la presentació de les dates:
```{r}
num_dates <- dim(confirmed_long_jhu)[2] - 4
dates <- seq(as.Date("2020/1/22"), by = "days", length.out = num_dates)
dates <- seq(as.Date("22-1-2020", format="%d-%m-%Y"), 
                  by = "days", length.out = num_dates)
```

I ara fem el gràfic de barres:
```{r}
casos <- confirmed_long_jhu[spain,-c(1:4)]
barplot(as.numeric(casos), names.arg = dates, 
          main = paste("Casos de COVID-19 en Espanya (", 
                       format(Sys.time(), '%d %B, %Y'), ")", sep = ""),
          sub="Font: John Hopkins University")
```


