How To Add Points To a Plot in R

Описание к видео How To Add Points To a Plot in R

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?su...


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.

Комментарии

Информация по комментариям в разработке