控制ggplot中的带宽

时间:2017-08-08 19:45:29

标签: r ggplot2 width geom-bar

我正在为一组标本中测试的一组病原体的抗菌素耐药性比例创建不同的图表。测试每种病原体的不同数量的抗微生物剂。因此,当我为每个病原体和每个样本创建图形时,带宽都是不同的。我试图设置width=.5, position = position_dodge(width=.2)但没有任何反应。 enter image description here enter image description here

prop <- read_csv("")
attach(prop)
propna<-na.omit(prop)


#calculate CI
results_CI<-cbind(propna, with (propna, binconf(propna$RES, propna$AST, method="wilson"))) 
results_CI<- rename(results_CI, c(antibiotic_label2="Antibiotic"))
results_CI<- rename(results_CI, c(PointEst="Resistance"))
results_CI$Antibiotic <- factor(results_CI$Antibiotic,levels=c("Amikacin","Spectinomycin", 
                                                               "Gentamicin", "Doripenem", "Ertapenem", "Imipenem", "Meropenem", "Ciprofloxacin", 
                                                               "Levofloxacin","Azithromycin",
                                                               "Ampicillin", "Colistin", "Minocycline", "Tigecycline","Cefoxitin", "Oxacillin", 
                                                               "Penicillin G", "Co-trimoxazole", 
                                                               "Cefotaxime", "Ceftazidime", "Cefixime","Ceftriaxone", "Cefepime"))

for(i in unique(results_CI$pathogen)) {

  ggplot(results_CI[results_CI$pathogen==i,], aes(y=Resistance, x=Antibiotic)
  ) +  scale_y_continuous(labels = percent_format(), limits=c(0,1)) +
    geom_bar( width=.5 ,position = position_dodge(width=.2), stat="identity")+ 
    geom_errorbar(aes(ymin=Lower, ymax=Upper),
                  width=.2,                    # Width of the error bars
                  position=position_dodge(.9))+
    coord_flip()+theme_classic()+facet_grid(~specimen)
  ggsave(file=paste("graphoverview", i, ".png", sep=""))
}

0 个答案:

没有答案