Here's minimal working problem. Consider the following data frame
DF <- data.frame(
y=1:10,
x=10:1,
z=rep(5,10),
a=11:20
)
Assume y
is my response. Now, for every pair plot (y,_)
in ggpairs(DF)
I want to mark point 1, 5 and 10 with a different color. How do I do this?
There doesn't seem to be an in-built way of doing this in
ggpairs
. There is a way round it, which is to modify the plot it produces. Of necessity, this is a "hacky" solution. It first requires you to specify the points panels (i.e. the ones you wish to modify), and of course the rows whose points you wish to be red:If you have done that correctly, the following code should transform your plots appropriately:
So now when we do:
we get
If you want to add a legend, do