0

I want to highlight 4 single points in a scatter plot with a box surrounding the name associated with the plot. I am using ggrepel to create the boxes surrounding the plots and to repel them.

This is the code I have:

library(ggplot2)

gg <- ggplot(X, aes(x = XX, y = XY)) + 
  geom_point(col = "steelblue", size = 3) +   
  geom_smooth(method = "lm", col = "firebrick", se = FALSE) +  
  labs(title = "XX vs XY", subtitle = "X", y = "XX", x = "XY") + 
  scale_x_continuous(breaks = seq(76, 82, 1)) + 
  scale_y_continuous(breaks = seq(15, 19, 1))

library(ggrepel)

gg + geom_text_repel(aes(label = Female), size = 3, data = X)
gg + geom_label_repel(aes(label = Female), size = 2, data = X)

With that code, I obtain boxes surrounding all the plots. However, I only want to have the boxes in 4 specific plots and no boxes in the other plots. How can I do that?

Thanks in advance! Regards, TD

  • Welcome to SO. It would be nice if you can provide some sample data. – Adela Nov 19 '18 at 14:34
  • Thanks! Unfortunately, it seems I cannot add pictures and when I add a table, it gets desestructured and its a completely mess to read. Sorry – Tyler Durden Nov 19 '18 at 15:26
  • 3
    You can `dput(X)` and post the result if you can publish your data: if they are too big, you can `dput(head(X, y))`, with `y` a sufficient number of row to have the issues you are getting. Do not be worried about the messy result, copy and paste it in `R` is going to have the data. If you cannot publish your data, add some fake one. – s__ Nov 20 '18 at 08:14

0 Answers0