2

I have an ethogram-like ggplot where I plot the value of a factor quadrant (1 to 4), which is plotted for each frame of a movie (frameID). The color is given by 3 animals that are being tracked.

I am fairly satisfied with the graph but the amount of points makes it difficult to see, even with alpha. I was wondering how to add position_dodge in a way that doesn't destroy the plot.

ggplot(dataframe) ,
         aes(frameID, quadrant, color=animal)) +
    geom_jitter(alpha=0.5) +
    scale_color_manual(values =  c("#1334C1","#84F619", "#F43900")) + 
    theme_classic()+ 
    theme(legend.position = 'none')

enter image description here

This link has useful info about dodging using geom_point. R: How to spread (jitter) points with respect to the x axis?

I can change to geom_point with height, which works but it produces something awful.

+ geom_point(position = position_jitter(w = 0, h = 2))

enter image description here

Update

Data lives in GitHub

Lowering the alpha or changing size helps, adds trouble when rescaling the image.

https://github.com/matiasandina/MLA2_Tracking/blob/master/demo_data/sample_data.csv

Update 2022

It's been a while since I posted this initially, my original thoughts changed and are better reflected here, but I am still looking for a ggplot2 version of doing this!

Matias Andina
  • 4,029
  • 4
  • 26
  • 58
  • Sharing some of your data would be useful. – Julius Vainora Mar 26 '18 at 01:28
  • @Julius please see my edit. I posted a small fraction because the data is huge. I was actually thinking about downsampling – Matias Andina Mar 26 '18 at 01:34
  • I'm afraid it doesn't really help, all the observations are from the second quadrant and the same animal. Perhaps you could pick a number of random rows. – Julius Vainora Mar 26 '18 at 01:37
  • @Julius My bad, messed up the subset – Matias Andina Mar 26 '18 at 01:44
  • 1
    Now the problem is that the sample data isn't enough to reproduce the issue.. Maybe you could upload the data somewhere or simulate it? As for the question itself, have you tried setting `alpha` to something quite lower, like 1 / 20, and adding, e.g., `size = 0.2` to `geom_jitter`? – Julius Vainora Mar 26 '18 at 01:51
  • 1
    As far as I know, a geom can have one `position` argument, and both dodging and jittering are implemented as positions. Easiest work around is probably to manually jitter your data (add a column of `runif(nrow(your_data), -.3, .3)` or something like that) and use the position argument for dodging. Julius's advice to reduce the size and alpha values will also help. – Gregor Thomas Mar 26 '18 at 02:01

0 Answers0