2

I am creating different graphs for the proportion of antimicrobial resistance for a set of pathogens tested in a set of specimens. Each pathogen is tested for a different number of antimicrobials. For this reason when I create the graphs for each pathogen and each specimen the band widths are all different. I tried to set width=.5, position = position_dodge(width=.2) but nothing happens. 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=""))
}
  • Please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by adding a minimal sample of your data that illustrates the problem. – tonytonov Aug 09 '17 at 08:49
  • I was going to add a link to dropbox but with the two pictures I maxed the links I can add. Is there another way? Should I omit the pictures and just put the dataframe? – B. Tornimbene Aug 10 '17 at 09:33
  • Just add the link as a comment and ping me, I'll add it to the post. – tonytonov Aug 10 '17 at 10:04

0 Answers0