Skip to content

Commit

Permalink
Fix downaload the data
Browse files Browse the repository at this point in the history
Fixed the issue with broken link to WHO by downloading the excel file and loading them to R using `readxl`.
  • Loading branch information
nimarafati committed Oct 6, 2023
1 parent dccbb82 commit 402171d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lab_graphics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -461,24 +461,22 @@ xpoints <- as.duration(timepoints[1] %--% timepoints) / ddays(1) / who.month

## Prepare reference data

Go to WHO website (http://www.who.int/childgrowth/standards/en/) and find out the link to the dataset of your concern, e.g. Weight for age, percentiles for girls have the following address: http://www.who.int/entity/childgrowth/standards/tab_wfa_girls_p_0_5.txt
Go to WHO website (http://www.who.int/childgrowth/standards/en/) and find out the link to the dataset of your concern, e.g. Weight for age, percentiles for girls have the following address: http://www.who.int/entity/childgrowth/standards/wfa_girls_p_0_5.xlsx

Load the data using URL from the previous point and the `read.table()` function.

<span style="color:red;">**ERROR:**</span> The URL below is broken therefore everything downstream is set to `eval=FALSE`. This needs to be fixed.

```{r,eval=FALSE}
uri <- "http://www.who.int/entity/childgrowth/standards/tab_wfa_girls_p_0_5.txt"
#uri <- "http://www.who.int/entity/childgrowth/standards/second_set/tab_hcfa_girls_p_0_5.txt"
#uri <- "http://www.who.int/entity/childgrowth/standards/tab_lhfa_girls_p_0_2.txt"
myData <-read.table(uri, header=T, sep='\t')
```{r,eval=T}
library(readxl)
uri <- "https://cdn.who.int/media/docs/default-source/child-growth/child-growth-standards/indicators/weight-for-age/tab_wfa_girls_p_0_5.xlsx?sfvrsn=666fe445_7"
local_file_path <- "../wfa_girls_p_0_5.xlsx" ## give the local path of the downloaded file
download.file(url = uri, destfile = local_file_path, mode = "wb")
myData <-read_excel(local_file_path)
```

## Built empty plot

Create an empty plot to show your and WHO data,

```{r,accordion=TRUE,fig.height=6,fig.width=10,eval=FALSE}
```{r,accordion=TRUE,fig.height=6,fig.width=10,eval=T}
plot(1, xlim=c(0, max(myData$Month)), type='n', bty='n', ylim=c(0, max(myData[,c(5:19)])), las=1, xlab='Month', ylab='kg')
grid()
```
Expand All @@ -487,7 +485,7 @@ grid()

Plot WHO mean and percentiles: P25, P75, P0.1 and P99.9, use different colors and line types to make the plot pretty.

```{r,fig.height=6,fig.width=10,echo=FALSE,eval=FALSE}
```{r,fig.height=6,fig.width=10,echo=FALSE,eval=T}
## CODE EVALUATED BUT NOT DISPLAYED ##
plot(1, xlim=c(0, max(myData$Month)), type='n', bty='n', ylim=c(0, max(myData[,c(5:19)])), las=1, xlab='Month', ylab='kg')
Expand All @@ -512,7 +510,7 @@ lines(myData$P999, col='tomato', lty=2)

Plot your data on top of the percentiles, mind the units so that they match with the WHO ones

```{r,fig.height=6,fig.width=10,echo=FALSE,eval=FALSE}
```{r,fig.height=6,fig.width=10,echo=FALSE,eval=T}
## CODE EVALUATED BUT NOT DISPLAYED ##
plot(1, xlim=c(0, max(myData$Month)), type='n', bty='n', ylim=c(0, max(myData[,c(5:19)])), las=1, xlab='Month', ylab='kg')
Expand All @@ -537,7 +535,7 @@ points(xpoints, weight/1000, pch=3, type='p', cex=.5)

Add descriptions of the confidence lines in the margins

```{r,fig.height=6,fig.width=10,echo=FALSE,eval=FALSE}
```{r,fig.height=6,fig.width=10,echo=FALSE,eval=T}
## CODE EVALUATED BUT NOT DISPLAYED ##
plot(1, xlim=c(0, max(myData$Month)), type='n', bty='n', ylim=c(0, max(myData[,c(5:19)])), las=1, xlab='Month', ylab='kg')
Expand Down

0 comments on commit 402171d

Please sign in to comment.