Question: I want to produce a facetted scatterplot with ggplot for each scatterplot contains the entire dataset in one colour, with a single ID (of that same dataset) in a different colour on top of the whole scatter. This is the data:

```
**trajectories**

X    Y    ID
2    4     1
1    6     1
2    4     1
1    8     2
3    7     2
1    5     2
1    4     3
1    6     3
7    4     3

```

I use the following code to produce scatterplots for each ID:

```
ggplot(trajectories, aes(x=X, y=Y)) + 
geom_point() + 
facet_wrap( ~ ID)

```

How can I print each of these scatterplots on a scatterplot of the whole dataset?

Answer: 
This should work:

```
ggplot(trajectories, aes(x=X, y=Y)) + 
  geom_point(color = ID) 

```

This will create a scatterplot with a color for each ID. If you want a scatter plot with just one color, just leave out the `color = id` bit.

To shade areas of a certain id, you can draw some inspiration from here:

[How can I overlay two dense scatter plots so that I can see the outlines of each in R or Matlab?](https://stackoverflow.com/questions/9706825/how-can-i-overlay-two-dense-scatter-plots-so-that-i-can-see-the-outlines-of-each/9711024#9711024)

It basically calculates a convex hull around subgroups and draws a polygon around it.
In base plots you can do something like:

```
  par(mfrow=c(length(unique(ID)),1))
    for(i in unique(ID)){ plot(X,Y,col=as.numeric(ID==i)+1)}

```

![enter image description here](https://i.stack.imgur.com/HHu1b.png)

If overplotting was a problem you can add jitter() or transparent colors.