Alison Bennett
Alison Bennett

Reputation: 315

How to place circles around specific data points on a scatter plot in R?

My question is two fold:

1) Is it possible to place a circle around specific data points on a scatter plot in R?
2) If so, how would I place separate circles of a defined radius around (5, 6) and (18, 23) given the following data.

x <- c(2, 5, 7, 9, 12, 16, 18, 21)
y <- c(3, 6, 10, 13, 15, 19, 23, 25)
plot(x, y)

(NB: This is not a request to colour specific data points on the plot, but to place a circle around them)

Upvotes: 6

Views: 8678

Answers (2)

Tad Dallas
Tad Dallas

Reputation: 1189

You can use the symbols function in base R, where the size vector is the radius you want around each point.

x <- c(2, 5, 7, 9, 12, 16, 18, 21)
y <- c(3, 6, 10, 13, 15, 19, 23, 25)
plot(x, y)
size=runif(length(x))
symbols(x,y,circles=size)

Upvotes: 5

MrFlick
MrFlick

Reputation: 206382

Check out the ?symbols help page for drawing circles

x <- c(2, 5, 7, 9, 12, 16, 18, 21)
y <- c(3, 6, 10, 13, 15, 19, 23, 25)
plot(x, y)
symbols(x=c(5,18), y=c(6,23), circles=rep(1,2), add=T, inches=F)

enter image description here

Upvotes: 7

Related Questions