SHARE
TWEET

grouped bar plots

a guest Mar 7th, 2015 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ggplot für mehrere bargraphen hintereinander
  2. library(ggplot2)
  3. library(plyr)
  4. library(reshape2)
  5.  
  6. melted <- melt(statistik_master_satz, id.vars=c("Droge"))
  7.  
  8. means <- ddply(melted, c("Droge", "variable"), summarise,
  9.                mean=mean(value)
  10. )
  11.  
  12. means$Droge <- factor(
  13.   means$Droge,
  14.   levels=rev(sort(unique(means$Droge))),
  15.   ordered=TRUE
  16. )
  17.  
  18. means2 <- means
  19. names(means2)[names(means2)=="mean"]  <- "Anzahl"
  20. names(means2)[names(means2)=="variable"]  <- "Legende"
  21.  
  22. ggplot(means2, aes(x=Droge, y=Anzahl, fill=Legende, horiz=TRUE)) +
  23.   geom_bar(stat="identity", position="dodge") +
  24.   coord_flip()
RAW Paste Data
Top