2017-10-17 5 views
0

Je veux faire un dotplot (stripchart) avec ggplot, mais le code semble empiler les points les uns sur les autres. Il n'y a pas plus de variation :(. Tout le monde sait comment je peux résoudre ce problème?Dotchart/Stripchart/Dotplot GGplot empile les points les uns sur les autres. Comment puis-je réparer cela?

df <- data.frame(City = c("AMS", "AMS", "AMS", "AMS", "BEL", "BEL", "BEL", "BEL"), 
      Month = c(4, 5, 6, 7, 4, 5, 6, 7), 
      Ratio = c(8, 9, 10, 5, 12, 13, 9, 10)) 

dp <- ggplot(df, aes(x = Month, y = Ratio, fill = City)) + 
    geom_dotplot() 

Répondre

1

Essayez cette

dp <- ggplot(df, aes(x = Month, y = Ratio, fill = City)) + 
geom_dotplot(position = position_jitter(width = 0.1, height = 0.1)) 
dp 

Vous pouvez préférer la position "esquiver"

dp <- ggplot(df, aes(x = Month, y = Ratio, fill = City)) + 
geom_dotplot(position = "dodge") 
dp 

Pour plus d'informations voir http://ggplot2.tidyverse.org/reference/position_dodge.html