How To Add Circles Around Specific Data Points in R
In this article, we will discuss how to add circles around specific data points in R Programming Language.
Method 1: Using geom_point method
The ggplot2 package in R is used to perform data visualization. To install this package type the below command in the terminal.
Aesthetic mappings can be created to the plot object to determine the relationship between the x and y axis respectively. Additional components can be added to the created ggplot object.
ggplot(data = NULL, mapping = aes())
- data – Default dataset to use for plot.
- mapping – List of aesthetic mappings to use for plot.
The geoms may also be specified with the additional mappings, like color to differently color the points pertaining to different groups.
geom_point(cond, pch, size, colour)
Circles can be added around data points by specifying the condition to apply on the data frame. The size of the circle and its corresponding colour can be specified using the arguments of the geom_point() method.
Method 2: Using symbols method
The plot() method in base R is used to plot a set of data points specified using the x and y coordinates. The symbols() method in R can be used for adding circles around them.
symbols (x, y , circles = c() , add , fg)
- x, y – the x and y co-ordinates for the centres of the symbols.
- circles – a vector giving the radii of the circles.
- add – In case the argument value of the add is TRUE, the symbols are added to an existing plot, otherwise a new plot is created.
- fg – a vector of the colour(s) the symbols are to be drawn in.
Example: This Code encircles the points belonging to coordinates (1,11) and (8,18) respectively with red and blue colours :
 "X coordinates"  1 2 3 4 5 6 7 8 9 10  "Y coordinates"  11 12 13 14 15 16 17 18 19 20