How to use ggplot2's geom_dotplot() with both fill and group

前端 未结 2 1559
北海茫月
北海茫月 2020-12-06 05:13

I really like the way the ggplot2::geom_dotplot() can nicely stack dots towards the middle of a category but I cannot seem to combine that with a fill color.

相关标签:
2条回答
  • 2020-12-06 05:34

    If you're open to a bit of a hacky solution just to get it how you want it to look... You can overwrite the fill command by simply providing it with a vector of color names:

    tmpData$colorname <- rep(c('red','blue','blue'),2)
    
    ggplot(tmpData, aes(x=x, y=y)) + 
      geom_dotplot(binaxis = "y", stackdir = "center", dotsize=4, fill=tmpData$colorname)
    

    0 讨论(0)
  • 2020-12-06 05:59

    I think you have to add the argument position = "dodge":

     ggplot(tmpData, aes(x = x, y = y, fill = fill,)) +
      geom_dotplot(binaxis = "y", stackdir = "center", dotsize = 4, position = "dodge")
    

    enter image description here

    0 讨论(0)
提交回复
热议问题