grouped barplot: order x-axis & keep constant bar width, in case of missing levels

前端 未结 4 560
情话喂你
情话喂你 2021-01-21 14:12

Here is my script (example inspired from here and using the reorder option from here):

library(ggplot2)
Animals <- read.table(
  header=TRUE, tex         


        
4条回答
  •  有刺的猬
    2021-01-21 14:26

    Along the same lines as the answer from user Alex, a less manual way of adding the categories might be

    d <- with(Animals, expand.grid(unique(Category), unique(Reason)))
    names(d) <- names(Animals)[1:2]
    Animals <- merge(d, Animals, all.x=TRUE)
    Animals$Species[is.na(Animals$Species)] <- 0
    

提交回复
热议问题