ggplot2 Error: Insufficient values in manual scale

前端 未结 2 1910
难免孤独
难免孤独 2020-12-16 15:56

When you have less colours defined with scale_fill_manual than levels in a factor, ggplot2 complains with this error message :

# B         


        
2条回答
  •  甜味超标
    2020-12-16 16:13

    My workaround so far is to provide ggplot2 with more colours, should any more levels appear, like this:

    # Basic definition of the plot
    plot <- ggplot(s4r, aes(x=DIM, y=nbexpress, fill=DIM))
    
    # Printing plot and options + faceting if any
    plot + geom_bar(stat="identity", show_guide=FALSE) + 
      scale_fill_manual(values=c("#CC0000", "#006600", "#669999", "#00CCCC", 
                                 "#660099", "#CC0066", "#FF9999", "#FF9900", 
                                 "black", "black", "black", "black", "black"))
    

提交回复
热议问题