Visualizing two or more data points where they overlap (ggplot R)

Cate picture Cate · Dec 23, 2017 · Viewed 20k times · Source

I have a scatterplot that has colour-coded data points. When two or more of the data points overlap only one of the colours is shown (whichever is first in the legend). Each of these data points represents an item and I need to show which items fall at each point on the scale. I'm using R (v.3.3.1). Would anyone have any suggestions as per how I could show that there are multiple items at each point on the scatterplot? Thanks in advance.

pdf('pedplot.pdf', height = 6, width = 10)
p3 <- ggplot(data=e4, aes(x=e4$domain, y=e4$ped)) + geom_point(aes(color = 
    e4$Database_acronym), size = 3, shape = 17) + 
    labs(x = "Domains", y = "Proportion of Elements per Domain", color = "Data 
    Sources") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) 
p3 dev.off();

Answer

Claus Wilke picture Claus Wilke · Dec 23, 2017

Separately from or in addition to jittering as mentioned here, you could also consider making the points partially transparent:

linecolors <- c("#714C02", "#01587A", "#024E37")
fillcolors <- c("#9D6C06", "#077DAA", "#026D4E")

# partially transparent points by setting `alpha = 0.5`
ggplot(mpg, aes(displ, cty, colour = drv, fill = drv)) +
  geom_point(position=position_jitter(h=0.1, w=0.1),
             shape = 21, alpha = 0.5, size = 3) +
  scale_color_manual(values=linecolors) +
  scale_fill_manual(values=fillcolors) +
  theme_bw()

enter image description here