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: 
The only way I can think of is to replicate the data set 3 times and set alternate ID for colours and a separate group for facetting. Assuming your `data.frame` is `df`

```
df$ID  <- NULL
df$ID1 <- rep(1:2, c(3,6))
df$ID2 <- c(2,2,2,1,1,1,2,2,2)
df$ID3 <- rep(2:1, c(6,3))
require(reshape2)
df.m <- melt(df, id.var=c("X", "Y"))
df.m$grp <- gl(3, 9)
df.m$value <- factor(df.m$value)

ggplot(data = df.m, aes(x = X, y = Y)) + geom_point(aes(colour = value)) + 
       facet_wrap(~ grp) + scale_colour_manual(values = c("blue", "black"))

```

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

Note that you have similar points within different groups and so some colours for that group are overwritten by the colour for the next group. For ex: (1,6) should be blue in the first facet but there is a (1,6) in ID=3 which therefore replaces blue to black.
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.