geom_dotplot continuous fill with discrete x

Viewed 117

I can get this visualization to work with mpg dataset, but am unable to recreate with my own data and am at a loss.

Looks good with mpg:

ggplot(mpg, aes(class, hwy, group= factor(displ)))+
 geom_dotplot(aes(fill = displ), binaxis = "y", stackdir = "center", binwidth = 0.5)

When I try to recreate with my own data, I lose the categorization along the x-axis. If I remove the "input" grouping it looks good, but I really want to have dots shaded by input.

x <- structure(list(model = c(rep("MODEL_PRED_180", 5),rep("MODEL_PRED_280", 5)), 
     size = c(170L, 179L, 183L, 181L, 186L, 244L, 236L, 239L, 230L, 247L), 
     input = c(750.2, 673.2, 770, 970.2, 601.7, 750.2, 673.2, 770, 970.2, 601.7)), class = "data.frame", row.names = c(NA, -10L))

ggplot(x, aes(model, size, group = factor(input)))+
  geom_dotplot(aes(fill = input), binaxis = "y", stackdir = "center", binwidth = 0.5)

I'm a relative R newbie, so any advice would be appreciated.


Update: I'm getting closer... I don't want the points to be outlined in separate colors, but changing any part of the following code results in complete loss of fill shading.

ggplot(x, aes(model, size, color = factor(input)))+
     geom_dotplot(aes(fill = input), binaxis = "y", stackdir = "center", binwidth = 2)

example

1 Answers

You can try this:

ggplot(x, aes(factor(model), size, group = factor(model)))+
    geom_dotplot(aes(fill = input), binaxis = "y", stackdir = "center", binwidth = 0.5)

enter image description here

Update

I include this update, could be helpful.

ggplot(x, aes(model, size, fill = factor(input)))+
  geom_dotplot(binaxis = "y", stackdir = "center", binwidth = 2)+
  scale_fill_brewer(palette="Blues")

enter image description here

Related