From 402171d8db642c2ee486ca527ebbfe0f56a4ae36 Mon Sep 17 00:00:00 2001 From: Nima Rafati Date: Fri, 6 Oct 2023 14:03:33 +0200 Subject: [PATCH] Fix downaload the data Fixed the issue with broken link to WHO by downloading the excel file and loading them to R using `readxl`. --- lab_graphics.Rmd | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lab_graphics.Rmd b/lab_graphics.Rmd index 43bc7ca..85b0822 100644 --- a/lab_graphics.Rmd +++ b/lab_graphics.Rmd @@ -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. -**ERROR:** 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() ``` @@ -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') @@ -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') @@ -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')