【发布时间】:2018-03-02 11:44:58
【问题描述】:
我想在 R 中使用 ggplot 或其他包绘制一个条形图,显示每个条形的多个 X 变量的值。
感谢您的帮助,并附上Akseer et al 的图形以显示我要绘制的图形。
下面我提供了复制此条形图的示例数据。
对于前两个代码,干预和组的间距和顺序旨在反映干预的分类,如示例图所示。这是因为并非所有干预措施都适合所有人。此外,在创建数据集后,需要删除不属于图 B 中给定干预的组的值(国家中位数)。
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")
现在我给小组。图 B 中的每个条形图显示了每个干预措施的全国中位数。前 7 组是绘制这些条形的全国中位数:
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
下面我提供最后一部分数据,即“省级覆盖”组的数据。这里有一个考虑因素:与上述 7 组(国家中位数)不同,下面所有这些“省级覆盖”变量都适用于 19 种干预措施中的每一种,如图 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]
同样,在创建数据集后,需要删除那些不属于图 B 中给定干预的组的值(国家中位数)。
我将不胜感激有关如何在 R 中重现此条形图的任何想法。
【问题讨论】: