Home > Back-end >  geom_dotplot with vertical stacking and colors
geom_dotplot with vertical stacking and colors

Time:11-24

I've looked at enter image description here

If I don't specify group=1 I get the colors, but the points are stacked:

ggplot(dfc, aes(color=g, fill=g))   geom_dotplot(aes(x=r), binwidth = 0.2)

enter image description here

I can get close with ggstance::position_dodgev(), but not quite:

ggplot(dfc, aes(color=g, fill=g))   geom_dotplot(position=ggstance::position_dodgev(height=0.025), aes(x=r), binwidth = 0.2)

enter image description here

CodePudding user response:

I think this might be what you're looking for. Let me know if this wasn't the answer you're looking for

ggplot(dfc, aes(x=r, y=g, color=g, fill=g))   
  geom_dotplot(stackgroups = TRUE, binwidth = 0.25, method = "histodot")  
  scale_x_continuous(breaks = seq(from = 2, to = 10, by = 2))

enter image description here

CodePudding user response:

Following the linked to post in the question and after some trial and error, I came up with this.

library(ggplot2)

ggplot(dfc, aes(x=r))   
  geom_dotplot(
    aes(color = g, fill = g), 
    stackgroups = TRUE,
    binpositions = "all", 
    binwidth = 0.2
  )

enter image description here

  • Related