0

Why does my graph plot 3 extra black dots?

df <- tibble::tibble(
  ID = 1:52,
  Variable = c(rep("A",24),rep("B",28)),
  Variable2 = c(rep("1",11),rep("2",7),rep("3",6),rep("1",11),rep("2",11),rep("3",6) ),
  value = c(72,92,77,84,44,85,38,79,77,84,72,81,83,90,96,30,83,76,90,89,81,87,98,83,56,75,59,60,60,62,74,50,75,67,62,90,78,72,70,85,84,55,75,53,82,62,47,57,52,50,63,61)
)

library(ggplot2)
ggplot(df, aes(x=Variable, y=value)) + 
  geom_boxplot() + geom_jitter(aes(color=Variable2), shape=16)

enter image description here

Ecg
  • 908
  • 1
  • 10
  • 28
  • 1
    Those black dots come from the `geom_boxplot` layer. The default is to draw points for "outliers" that are more than 1.5 times the IQR from the 1st and 3rd quartiles. You can turn them off using the methods in this existing question: https://stackoverflow.com/questions/5677885/ignore-outliers-in-ggplot2-boxplot – MrFlick Jan 21 '21 at 18:32
  • Thanks, I had never come across something like this until now! – Ecg Jan 21 '21 at 18:39
  • For future reference, this is what worked for me: "ggplot(df, aes(x=Variable, y=value)) + geom_boxplot(outlier.colour = NA) + geom_jitter(aes(color=Variable2), shape=16) adding the outlier.colour=NA" – Ecg Jan 27 '21 at 15:19

0 Answers0