How To Add Points To a Plot in R

Channel:
Subscribers:
44,100
Published on ● Video Link: https://www.youtube.com/watch?v=tnzwbG_UixM



Category:
Guide
Duration: 3:37
6,427 views
51


This video shows how to add points at arbitrary x, y positions to plots in base R and ggplot2.

If you find this video useful, like, share and subscribe to support the channel!

► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1


Code used in this R Code Clip:

# Add points to a base R plot

# Create plot
plot(mtcars$mpg, mtcars$hp)

# Add a point
points(x = 15, # point x coordinate
y = 100, # point y coordinate
pch = 15, # point shape
col = "red", # point color
cex = 3) # point size

# Add another point
points(x = 25, # point x coordinate
y = 250, # point y coordinate
pch = 17, # point shape
col = "blue", # point color
cex = 4) # point size


# Add points in ggplot
library(tidyverse)

ggplot(data = mtcars, aes(x = mpg, y = hp)) +
geom_point() + # Create scatterplot
geom_point(aes(x=15, y=100), # Add a point
col ="red",
shape = 15,
size = 8) +
annotate("point", x=25, y=250, # Add another point
col ="blue",
shape = 17,
size = 10)


* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones.







Tags:
plot points in r
plot points in ggplot
plot points in ggplot2
add points to a plot in r
add points to a plot in ggplot
add points to a plot in ggplot2
plot arbitrary points in r
r plotting
r plot points
ggplot plot points
ggplot add points
r add points
r plotting basics
ggplot plotting basics
geom_point
ggplot annotation
r points
r points function
base r plot points