How do I place circles around specific data points in a scatter plot in R?

My question is twofold:

1) Is it possible to place a circle around specific data points on a scatter plot in R?
2) If so, how would one place individual circles of a certain radius around (5, 6) and (18, 23), taking into account 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 for the color of specific data points in the graph, but to place a circle around them)

+3


source to share


2 answers


Review the reference page ?symbols

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

+5


source


You can use a function symbols

in base R where the vector size

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)

      

+4


source







All Articles