I want to plot in R using ggplot or another package a bar chart showing values of multiple X variables per bar.
I would appreciate your help to do so and have attached a Figure by Akseer et al to show the graph I want to draw.
Below I provide sample data to replicate this bar chart.
For the first two codes, the spacing and order of interventions and groups aim to reflect the categorization of the interventions as in the example Figure. This is because not all interventions are for everybody. Also, those values for groups (national medians) that are not part of a given intervention in Figure B will need to be dropped after the dataset is created.
Interventions<-c("Demand of family planning satisfied", ## interventions for 1s group
"ANC 1+", ## interventions for 2nd group
"ANC 4+",
"ANC by skilled provider",
"Protected against neonatal tetanus",
"SBA", ## interventions for 3rd group
"Facility deliveries",
"Early breastfeeding", ## interventions for 4th group
"Exclusive breastfeeding at 6 months", ## interventions for 5th group
"Minimum meal frequency",
"BCG",
"Penta3",
"Measles",
"Received vitamin A during the last 6 months",
"Diarrhoea treatment (ORS)", ## interventions for 6th group
"Care seeking for pneumonia",
"Antibiotics for pneumonia",
"Improved drinking water sources", ## interventions for 7th group
"Improved sanitation facilities")
Now I give the groups. Each bar in Figure B shows the national median for each intervention. These first 7 groups are national medians to draw those bars:
Prepregnancy<- (sample(1:100, 19, replace=TRUE)) ## 1st group
Pregnancy<-(sample(1:100, 19, replace=TRUE)) ## 2nd group
Birth<-(sample(1:100, 19, replace=TRUE)) ## 3rd group
Postnatal<-(sample(1:100, 19, replace=TRUE)) ## 4th group
Infancy<-sample(1:100, 19, replace=TRUE) ## 5th group
Childhood<-sample(1:100, 19, replace=TRUE) ## 6th group
Other<-sample(1:100, 19, replace=TRUE) ## 7th group
Below I provide the last part of the data, that's, data for the group "provincial coverage". There is one consideration here: unlike the 7 groups above (national medians), all of these "provincial coverage" variables below apply for each of the 19 interventions as can be seen in Figure B.
Provincial1<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial2<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial3<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial4<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial5<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial6<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial7<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial8<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial9<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
Provincial10<-sample(1:100, 19, replace=TRUE) ## provincial level observations for each of the 19 interventions
mydata_B<-data.frame(Interventions, Prepregnancy, Pregnancy,
Birth, Postnatal, Infancy, Childhood, Other,
Provincial1, Provincial2, Provincial3,
Provincial4, Provincial5,
Provincial6, Provincial7, Provincial8,
Provincial9, Provincial10)
rownames(mydata_B) <- mydata_B[,1]
dtFig3B <- mydata_B[,-1]
And, again, those values for groups (national medians) that are not part of a given intervention in Figure B will need to be dropped after the dataset is created.
I would appreciate any ideas on how to reproduce this bar chart in R.