SHARE
TWEET

R stacked bar plots

a guest Mar 7th, 2015 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. melted <- melt(beitraege, id.vars=c("Droge"))
  2.  
  3. melted$Droge <- factor(
  4.   melted$Droge,
  5.   levels=rev(sort(unique(melted$Droge))),
  6.   ordered=TRUE
  7. )
  8.  
  9. melted2 <- melted[order(melted$value),]
  10.  
  11. melted2 <- within(melted2, {
  12.   Droge <- factor(Droge, levels = names(sort(tapply(value, Droge, sum))))
  13. })
  14.  
  15. ggplot(melted2, aes(x= Droge, y = value, fill = variable, order = variable)) +
  16.   geom_bar(stat = "identity") +
  17.   coord_flip()
RAW Paste Data
Top